aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>2018-04-23 10:35:56 +0200
committerGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>2018-04-23 10:41:27 +0200
commit767c0e538b6b7c751784444fd6c676668e3a1b01 (patch)
tree6708c8474e2a2749f737817840b0f050d5236e44
parent0682b86504faf606b9017bc82bdbabd3af237db6 (diff)
downloadansible-kong-app-767c0e538b6b7c751784444fd6c676668e3a1b01.tar.gz
ansible-kong-app-767c0e538b6b7c751784444fd6c676668e3a1b01.tar.zst
ansible-kong-app-767c0e538b6b7c751784444fd6c676668e3a1b01.zip
setup an array of services
-rw-r--r--README.md29
-rw-r--r--defaults/main.yml3
-rw-r--r--tasks/kong-app.yml9
-rw-r--r--tasks/main.yml5
-rw-r--r--tasks/plugins.yml6
-rw-r--r--tasks/routes.yml6
-rw-r--r--tests/test.retry1
-rw-r--r--vars/main.yml3
8 files changed, 32 insertions, 30 deletions
diff --git a/README.md b/README.md
index 5cf5f18..074e830 100644
--- a/README.md
+++ b/README.md
@@ -13,16 +13,17 @@ Role Variables
13 13
14* `kong_app_admin_url` the kong admin url (mandatory). 14* `kong_app_admin_url` the kong admin url (mandatory).
15* `kong_app_admin_apikey` the apikey to use kong admin api. Default to "" 15* `kong_app_admin_apikey` the apikey to use kong admin api. Default to ""
16* `kong_app_service_name` the nameof the service to create for this app, mandatory 16* `kong_services` an array of services to setup (default to [])
17* `kong_app_service_url` the url of the backend of the app, mandatory 17 * `name` the name of the service to create for this app, mandatory
18* `kong_app_plugins` An array of plugins to activate with their name and config in a dict 18 * `url` the url of the backend of the app, mandatory
19 * `name` 19 * `plugins` An array of plugins to activate with their name and config in a dict
20 * `config` 20 * `name`
21* `kong_app_routes` An array of routes to create for this app. 21 * `config`
22 * `hosts` 22 * `routes` An array of routes to create for this service.
23 * `paths` 23 * `hosts`
24 * `protocols` 24 * `paths`
25 * `methods` 25 * `protocols`
26 * `methods`
26 27
27Dependencies 28Dependencies
28------------ 29------------
@@ -35,10 +36,10 @@ Example Playbook
35 - hosts: localhost 36 - hosts: localhost
36 roles: 37 roles:
37 - { role: kong-app, kong_app_admin_url: http://localhost:8001, 38 - { role: kong-app, kong_app_admin_url: http://localhost:8001,
38 kong_app_service_name: example, 39 kong_app_services: [ name:example,
39 kong_app_service_url: http://example.com, 40 url: http://example.com,
40 kong_app_plugins: [], 41 plugins: [],
41 kong_app_routes: [ { hosts: [my.kong.example], paths: [/] } ] 42 routes: [ { hosts: [my.kong.example], paths: [/] } ]]
42 } 43 }
43 44
44License 45License
diff --git a/defaults/main.yml b/defaults/main.yml
index d75773b..e2de8f5 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,4 +1,3 @@
1--- 1---
2kong_app_admin_apikey: "" 2kong_app_admin_apikey: ""
3kong_app_plugins: [] 3kong_services: []
4kong_app_routes: []
diff --git a/tasks/kong-app.yml b/tasks/kong-app.yml
index df95f2e..f94f044 100644
--- a/tasks/kong-app.yml
+++ b/tasks/kong-app.yml
@@ -1,6 +1,6 @@
1- name: Check if service exists 1- name: Check if service exists
2 uri: 2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}" 3 url: "{{ kong_app_admin_url }}/services/{{ service.name }}"
4 method: GET 4 method: GET
5 headers: 5 headers:
6 apikey: "{{ kong_app_admin_apikey }}" 6 apikey: "{{ kong_app_admin_apikey }}"
@@ -9,15 +9,18 @@
9 9
10- name: Update or Create service 10- name: Update or Create service
11 uri: 11 uri:
12 url: "{{ kong_app_admin_url }}/services/{{ exists_service | ternary('', kong_app_service_name) }}" 12 url: "{{ kong_app_admin_url }}/services/{{ exists_service | ternary('', service.name) }}"
13 method: "{{ exists_service | ternary('POST', 'PATCH') }}" 13 method: "{{ exists_service | ternary('POST', 'PATCH') }}"
14 body: "{{ kong_app_service_body | to_json }}" 14 body: "{{ service_body | to_json }}"
15 status_code: 200,201 15 status_code: 200,201
16 headers: 16 headers:
17 apikey: "{{ kong_app_admin_apikey }}" 17 apikey: "{{ kong_app_admin_apikey }}"
18 Content-Type: application/json 18 Content-Type: application/json
19 vars: 19 vars:
20 exists_service: "{{ kong_app_check_service.status|default(404) == 404 }}" 20 exists_service: "{{ kong_app_check_service.status|default(404) == 404 }}"
21 service_body:
22 name: "{{ service.name }}"
23 url: "{{ service.url }}"
21 24
22- name: Setup plugins 25- name: Setup plugins
23 import_tasks: plugins.yml 26 import_tasks: plugins.yml
diff --git a/tasks/main.yml b/tasks/main.yml
index 4bb562f..4bd42c8 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,5 +1,8 @@
1--- 1---
2- name: Include kong-app tasks 2- name: Include kong-app tasks
3 import_tasks: kong-app.yml 3 include_tasks: kong-app.yml
4 tags: 4 tags:
5 - kong-app 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
index f096d4b..3ae0fbe 100644
--- a/tasks/plugins.yml
+++ b/tasks/plugins.yml
@@ -1,6 +1,6 @@
1- name: Get plugins 1- name: Get plugins
2 uri: 2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" 3 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/plugins"
4 method: GET 4 method: GET
5 validate_certs: no 5 validate_certs: no
6 headers: 6 headers:
@@ -9,14 +9,14 @@
9 9
10- name: Setup plugin 10- name: Setup plugin
11 uri: 11 uri:
12 url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ kong_app_service_name ~ '/plugins','plugins/' ~ current_config.id) }}" 12 url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ service.name ~ '/plugins','plugins/' ~ current_config.id) }}"
13 method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}" 13 method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}"
14 body: "{{ plugin | combine(current_body) | to_json }}" 14 body: "{{ plugin | combine(current_body) | to_json }}"
15 headers: 15 headers:
16 apikey: "{{ kong_app_admin_apikey }}" 16 apikey: "{{ kong_app_admin_apikey }}"
17 Content-Type: application/json 17 Content-Type: application/json
18 status_code: 200,201 18 status_code: 200,201
19 with_items: "{{ kong_app_plugins }}" 19 with_items: "{{ service.plugins | default([]) }}"
20 loop_control: 20 loop_control:
21 loop_var: plugin 21 loop_var: plugin
22 vars: 22 vars:
diff --git a/tasks/routes.yml b/tasks/routes.yml
index 4581e8c..881fc96 100644
--- a/tasks/routes.yml
+++ b/tasks/routes.yml
@@ -1,6 +1,6 @@
1- name: Get app routes 1- name: Get app routes
2 uri: 2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" 3 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes"
4 method: GET 4 method: GET
5 validate_certs: no 5 validate_certs: no
6 headers: 6 headers:
@@ -9,14 +9,14 @@
9 9
10- name: Setup route 10- name: Setup route
11 uri: 11 uri:
12 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" 12 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes"
13 method: POST 13 method: POST
14 body: "{{ route | to_json }}" 14 body: "{{ route | to_json }}"
15 headers: 15 headers:
16 apikey: "{{ kong_app_admin_apikey }}" 16 apikey: "{{ kong_app_admin_apikey }}"
17 Content-Type: application/json 17 Content-Type: application/json
18 status_code: 201 18 status_code: 201
19 with_items: "{{ kong_app_routes }}" 19 with_items: "{{ service.routes | default([]) }}"
20 loop_control: 20 loop_control:
21 loop_var: route 21 loop_var: route
22 22
diff --git a/tests/test.retry b/tests/test.retry
deleted file mode 100644
index 2fbb50c..0000000
--- a/tests/test.retry
+++ /dev/null
@@ -1 +0,0 @@
1localhost
diff --git a/vars/main.yml b/vars/main.yml
index 02f5cd6..ed97d53 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -1,4 +1 @@
1--- ---
2kong_app_service_body:
3 name: "{{ kong_app_service_name }}"
4 url: "{{ kong_app_service_url }}"