From ad5e125af59a34020943158999564af4f3a41a59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ga=C3=ABtan=20Duchaussois?= Date: Fri, 20 Apr 2018 12:14:40 +0200 Subject: [PATCH] After testing --- meta/main.yml | 4 ++-- tasks/kong-app.yml | 18 +++++++++--------- tasks/plugins.yml | 16 +++++++--------- tasks/routes.yml | 10 ++++------ 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/meta/main.yml b/meta/main.yml index e2b8be4..a2ae975 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,7 +1,7 @@ galaxy_info: author: FretLink team description: Love and trucks - company: FretLink + company: FretLink # If the issue tracker for your role is not on github, uncomment the # next line and provide a value @@ -14,7 +14,7 @@ galaxy_info: # - GPLv3 # - Apache # - CC-BY - license: TBD + license: TBD min_ansible_version: 2.4 diff --git a/tasks/kong-app.yml b/tasks/kong-app.yml index d50c193..e162c09 100644 --- a/tasks/kong-app.yml +++ b/tasks/kong-app.yml @@ -7,15 +7,15 @@ status_code: 200,404 register: kong_app_check_service -#- name: Update or Create service -# uri: -# url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}" -# method: "{{ (kong_app_check_service.status_code == 404) | ternary ('POST', 'PATCH') }}" -# body: "{{ kong_app_service_body | to_json }}" -# headers: -# apikey: "{{ kong_app_admin_apikey }}" -# Content-Type: application/json -# status_code: 200,201 +- 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') }}" + body: "{{ kong_app_service_body | to_json }}" + status_code: 200,201 + headers: + apikey: "{{ kong_app_admin_apikey }}" + Content-Type: application/json - name: Setup plugins import_tasks: plugins.yml diff --git a/tasks/plugins.yml b/tasks/plugins.yml index c8f165c..84f3d49 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -3,16 +3,14 @@ url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" method: GET validate_certs: no + headers: + apikey: "{{ kong_app_admin_apikey }}" register: kong_app_service_plugins_check -- name: Set plugins facts - set_fact: - kong_app_current_plugins: "{{ kong_app_service_plugins_check.json | default('{}') | from_json }}" - -- name: Setup plugin {{ plugin.name }} +- name: Setup plugin uri: - url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" - method: "{{ (current_config == {}) | ternary ('POST', 'PATCH') }}" + 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') }}" body: "{{ plugin | combine(current_body) | to_json }}" headers: apikey: "{{ kong_app_admin_apikey }}" @@ -22,7 +20,7 @@ loop_control: loop_var: plugin vars: - current_config: "{{ kong_app_current_plugins.data | selectattr('name', plugin.name) | first |default({}) }}" + current_config: "{{ kong_app_service_plugins_check.json.data | selectattr('name', 'equalto', plugin.name) | first |default({\"id\": ''}) }}" current_id_hash: - id: "{{ current_config.id | default('')}}" + id: "{{ current_config.id }}" current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}" diff --git a/tasks/routes.yml b/tasks/routes.yml index 1a9f6db..bbcdb76 100644 --- a/tasks/routes.yml +++ b/tasks/routes.yml @@ -3,12 +3,10 @@ url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" method: GET validate_certs: no + headers: + apikey: "{{ kong_app_admin_apikey }}" register: kong_app_service_routes_check -- name: Set routes facts - set_fact: - kong_app_current_routes: "{{ kong_app_service_routes_check.json |default('{\"data\": []}') | from_json }}" - - name: Setup route uri: url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" @@ -24,9 +22,9 @@ - name: Delete old routes uri: - url: "{{ kong_app_admin_url }}/services/routes/{{ item.id }}" + url: "{{ kong_app_admin_url }}/routes/{{ item.id }}" method: DELETE headers: apikey: "{{ kong_app_admin_apikey }}" status_code: 204 - with_items: "{{ kong_app_current_routes.data }}" + with_items: "{{ kong_app_service_routes_check.json.data }}" -- 2.41.0