From 1a33ca3184dbea838ea083a7cf026cf5884dc3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Fri, 20 Apr 2018 10:04:41 +0200 Subject: initial version --- tasks/plugins.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tasks/plugins.yml (limited to 'tasks/plugins.yml') diff --git a/tasks/plugins.yml b/tasks/plugins.yml new file mode 100644 index 0000000..c8f165c --- /dev/null +++ b/tasks/plugins.yml @@ -0,0 +1,28 @@ +- name: Get plugins + uri: + url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" + method: GET + validate_certs: no + 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 }} + uri: + url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" + method: "{{ (current_config == {}) | ternary ('POST', 'PATCH') }}" + body: "{{ plugin | combine(current_body) | to_json }}" + headers: + apikey: "{{ kong_app_admin_apikey }}" + Content-Type: application/json + status_code: 200,201 + with_items: "{{ kong_app_plugins }}" + loop_control: + loop_var: plugin + vars: + current_config: "{{ kong_app_current_plugins.data | selectattr('name', plugin.name) | first |default({}) }}" + current_id_hash: + id: "{{ current_config.id | default('')}}" + current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}" -- cgit v1.2.3 From ad5e125af59a34020943158999564af4f3a41a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Fri, 20 Apr 2018 12:14:40 +0200 Subject: After testing --- tasks/plugins.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to '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) }}" -- cgit v1.2.3 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 --- tasks/plugins.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to '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 -- cgit v1.2.3 From 0682b86504faf606b9017bc82bdbabd3af237db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Fri, 20 Apr 2018 15:00:52 +0200 Subject: fix deprecation warning --- tasks/plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tasks/plugins.yml') diff --git a/tasks/plugins.yml b/tasks/plugins.yml index c03bca7..f096d4b 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -25,4 +25,4 @@ 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 + when: not kong_app_service_plugins_check is skipped -- cgit v1.2.3 From 767c0e538b6b7c751784444fd6c676668e3a1b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Mon, 23 Apr 2018 10:35:56 +0200 Subject: setup an array of services --- tasks/plugins.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tasks/plugins.yml') diff --git a/tasks/plugins.yml b/tasks/plugins.yml index f096d4b..3ae0fbe 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -1,6 +1,6 @@ - name: Get plugins uri: - url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" + url: "{{ kong_app_admin_url }}/services/{{ service.name }}/plugins" method: GET validate_certs: no headers: @@ -9,14 +9,14 @@ - name: Setup plugin uri: - url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ kong_app_service_name ~ '/plugins','plugins/' ~ current_config.id) }}" + url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ 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 }}" Content-Type: application/json status_code: 200,201 - with_items: "{{ kong_app_plugins }}" + with_items: "{{ service.plugins | default([]) }}" loop_control: loop_var: plugin vars: -- cgit v1.2.3