From d213edd127a145821e419e80104a838da421e7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Fri, 20 Apr 2018 14:40:33 +0200 Subject: add travis configuration and fix tests --- .travis.yml | 32 ++++++++++++++++++++++++++++++++ tasks/kong-app.yml | 6 ++++-- tasks/plugins.yml | 6 ++++-- tasks/routes.yml | 1 + tests/inventory | 2 +- 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..812d0fe --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + - pip install ansible-lint + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + - ansible-lint . + - ansible-playbook tests/test.yml -i tests/inventory -C -D + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/tasks/kong-app.yml b/tasks/kong-app.yml index e162c09..df95f2e 100644 --- a/tasks/kong-app.yml +++ b/tasks/kong-app.yml @@ -9,13 +9,15 @@ - name: Update or Create service uri: - url: "{{ kong_app_admin_url }}/services/{{ (kong_app_check_service.status == 404) | ternary('', kong_app_service_name) }}" - method: "{{ (kong_app_check_service.status == 404) | ternary('POST', 'PATCH') }}" + url: "{{ kong_app_admin_url }}/services/{{ exists_service | ternary('', kong_app_service_name) }}" + method: "{{ exists_service | ternary('POST', 'PATCH') }}" body: "{{ kong_app_service_body | to_json }}" status_code: 200,201 headers: apikey: "{{ kong_app_admin_apikey }}" Content-Type: application/json + vars: + exists_service: "{{ kong_app_check_service.status|default(404) == 404 }}" - name: Setup plugins import_tasks: plugins.yml diff --git a/tasks/plugins.yml b/tasks/plugins.yml index 84f3d49..c03bca7 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -9,8 +9,8 @@ - name: Setup plugin uri: - url: "{{ kong_app_admin_url }}/{{ (current_config.id == '') | ternary('services/' ~ kong_app_service_name ~ '/plugins','plugins/' ~ current_config.id) }}" - method: "{{ (current_config.id == '') | ternary ('POST', 'PATCH') }}" + url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ kong_app_service_name ~ '/plugins','plugins/' ~ current_config.id) }}" + method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}" body: "{{ plugin | combine(current_body) | to_json }}" headers: apikey: "{{ kong_app_admin_apikey }}" @@ -24,3 +24,5 @@ current_id_hash: id: "{{ current_config.id }}" current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}" + exists_plugin: "{{ current_id_hash.id == '' }}" + when: not kong_app_service_plugins_check|skipped diff --git a/tasks/routes.yml b/tasks/routes.yml index bbcdb76..d4d912f 100644 --- a/tasks/routes.yml +++ b/tasks/routes.yml @@ -28,3 +28,4 @@ apikey: "{{ kong_app_admin_apikey }}" status_code: 204 with_items: "{{ kong_app_service_routes_check.json.data }}" + when: not kong_app_service_routes_check|skipped diff --git a/tests/inventory b/tests/inventory index 878877b..49d4fe2 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1,2 +1,2 @@ -localhost +localhost ansible_connection=local -- cgit v1.2.3