aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks
diff options
context:
space:
mode:
authorGaƫtan <36162164+gaetanfl@users.noreply.github.com>2018-04-23 10:57:50 +0200
committerGitHub <noreply@github.com>2018-04-23 10:57:50 +0200
commit208d503983ba44c64f92c20e8d062905a2ac47f5 (patch)
tree6708c8474e2a2749f737817840b0f050d5236e44 /tasks
parent530dddec969df385e9aa29af0917f6ca97094d68 (diff)
parent767c0e538b6b7c751784444fd6c676668e3a1b01 (diff)
downloadansible-kong-app-208d503983ba44c64f92c20e8d062905a2ac47f5.tar.gz
ansible-kong-app-208d503983ba44c64f92c20e8d062905a2ac47f5.tar.zst
ansible-kong-app-208d503983ba44c64f92c20e8d062905a2ac47f5.zip
Merge pull request #1 from gaetanfl/initial_versionv0.1
initial version
Diffstat (limited to 'tasks')
-rw-r--r--tasks/kong-app.yml29
-rw-r--r--tasks/main.yml8
-rw-r--r--tasks/plugins.yml28
-rw-r--r--tasks/routes.yml31
4 files changed, 96 insertions, 0 deletions
diff --git a/tasks/kong-app.yml b/tasks/kong-app.yml
new file mode 100644
index 0000000..f94f044
--- /dev/null
+++ b/tasks/kong-app.yml
@@ -0,0 +1,29 @@
1- name: Check if service exists
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ service.name }}"
4 method: GET
5 headers:
6 apikey: "{{ kong_app_admin_apikey }}"
7 status_code: 200,404
8 register: kong_app_check_service
9
10- name: Update or Create service
11 uri:
12 url: "{{ kong_app_admin_url }}/services/{{ exists_service | ternary('', service.name) }}"
13 method: "{{ exists_service | ternary('POST', 'PATCH') }}"
14 body: "{{ service_body | to_json }}"
15 status_code: 200,201
16 headers:
17 apikey: "{{ kong_app_admin_apikey }}"
18 Content-Type: application/json
19 vars:
20 exists_service: "{{ kong_app_check_service.status|default(404) == 404 }}"
21 service_body:
22 name: "{{ service.name }}"
23 url: "{{ service.url }}"
24
25- name: Setup plugins
26 import_tasks: plugins.yml
27
28- name: Setup routes
29 import_tasks: routes.yml
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..4bd42c8
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,8 @@
1---
2- name: Include kong-app tasks
3 include_tasks: kong-app.yml
4 tags:
5 - kong-app
6 with_items: "{{ kong_services }}"
7 loop_control:
8 loop_var: service
diff --git a/tasks/plugins.yml b/tasks/plugins.yml
new file mode 100644
index 0000000..3ae0fbe
--- /dev/null
+++ b/tasks/plugins.yml
@@ -0,0 +1,28 @@
1- name: Get plugins
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/plugins"
4 method: GET
5 validate_certs: no
6 headers:
7 apikey: "{{ kong_app_admin_apikey }}"
8 register: kong_app_service_plugins_check
9
10- name: Setup plugin
11 uri:
12 url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ service.name ~ '/plugins','plugins/' ~ current_config.id) }}"
13 method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}"
14 body: "{{ plugin | combine(current_body) | to_json }}"
15 headers:
16 apikey: "{{ kong_app_admin_apikey }}"
17 Content-Type: application/json
18 status_code: 200,201
19 with_items: "{{ service.plugins | default([]) }}"
20 loop_control:
21 loop_var: plugin
22 vars:
23 current_config: "{{ kong_app_service_plugins_check.json.data | selectattr('name', 'equalto', plugin.name) | first |default({\"id\": ''}) }}"
24 current_id_hash:
25 id: "{{ current_config.id }}"
26 current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}"
27 exists_plugin: "{{ current_id_hash.id == '' }}"
28 when: not kong_app_service_plugins_check is skipped
diff --git a/tasks/routes.yml b/tasks/routes.yml
new file mode 100644
index 0000000..881fc96
--- /dev/null
+++ b/tasks/routes.yml
@@ -0,0 +1,31 @@
1- name: Get app routes
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes"
4 method: GET
5 validate_certs: no
6 headers:
7 apikey: "{{ kong_app_admin_apikey }}"
8 register: kong_app_service_routes_check
9
10- name: Setup route
11 uri:
12 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes"
13 method: POST
14 body: "{{ route | to_json }}"
15 headers:
16 apikey: "{{ kong_app_admin_apikey }}"
17 Content-Type: application/json
18 status_code: 201
19 with_items: "{{ service.routes | default([]) }}"
20 loop_control:
21 loop_var: route
22
23- name: Delete old routes
24 uri:
25 url: "{{ kong_app_admin_url }}/routes/{{ item.id }}"
26 method: DELETE
27 headers:
28 apikey: "{{ kong_app_admin_apikey }}"
29 status_code: 204
30 with_items: "{{ kong_app_service_routes_check.json.data }}"
31 when: not kong_app_service_routes_check is skipped