diff options
author | Gaëtan Duchaussois <gaetan.duchaussois@fretlink.com> | 2018-04-20 12:14:40 +0200 |
---|---|---|
committer | Gaëtan Duchaussois <gaetan.duchaussois@fretlink.com> | 2018-04-20 12:25:34 +0200 |
commit | ad5e125af59a34020943158999564af4f3a41a59 (patch) | |
tree | 4e559788feeb9fe0ff52e0e168eac28b9c9582b3 | |
parent | 1a33ca3184dbea838ea083a7cf026cf5884dc3f4 (diff) | |
download | ansible-kong-app-ad5e125af59a34020943158999564af4f3a41a59.tar.gz ansible-kong-app-ad5e125af59a34020943158999564af4f3a41a59.tar.zst ansible-kong-app-ad5e125af59a34020943158999564af4f3a41a59.zip |
After testing
-rw-r--r-- | meta/main.yml | 4 | ||||
-rw-r--r-- | tasks/kong-app.yml | 18 | ||||
-rw-r--r-- | tasks/plugins.yml | 16 | ||||
-rw-r--r-- | 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 @@ | |||
1 | galaxy_info: | 1 | galaxy_info: |
2 | author: FretLink team | 2 | author: FretLink team |
3 | description: Love and trucks | 3 | description: Love and trucks |
4 | company: FretLink | 4 | company: FretLink |
5 | 5 | ||
6 | # If the issue tracker for your role is not on github, uncomment the | 6 | # If the issue tracker for your role is not on github, uncomment the |
7 | # next line and provide a value | 7 | # next line and provide a value |
@@ -14,7 +14,7 @@ galaxy_info: | |||
14 | # - GPLv3 | 14 | # - GPLv3 |
15 | # - Apache | 15 | # - Apache |
16 | # - CC-BY | 16 | # - CC-BY |
17 | license: TBD | 17 | license: TBD |
18 | 18 | ||
19 | min_ansible_version: 2.4 | 19 | min_ansible_version: 2.4 |
20 | 20 | ||
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 @@ | |||
7 | status_code: 200,404 | 7 | status_code: 200,404 |
8 | register: kong_app_check_service | 8 | register: kong_app_check_service |
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/{{ kong_app_service_name }}" | 12 | url: "{{ kong_app_admin_url }}/services/{{ (kong_app_check_service.status == 404) | ternary('', kong_app_service_name) }}" |
13 | # method: "{{ (kong_app_check_service.status_code == 404) | ternary ('POST', 'PATCH') }}" | 13 | method: "{{ (kong_app_check_service.status == 404) | ternary('POST', 'PATCH') }}" |
14 | # body: "{{ kong_app_service_body | to_json }}" | 14 | body: "{{ kong_app_service_body | to_json }}" |
15 | # headers: | 15 | status_code: 200,201 |
16 | # apikey: "{{ kong_app_admin_apikey }}" | 16 | headers: |
17 | # Content-Type: application/json | 17 | apikey: "{{ kong_app_admin_apikey }}" |
18 | # status_code: 200,201 | 18 | Content-Type: application/json |
19 | 19 | ||
20 | - name: Setup plugins | 20 | - name: Setup plugins |
21 | import_tasks: plugins.yml | 21 | 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 @@ | |||
3 | url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" | 3 | url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" |
4 | method: GET | 4 | method: GET |
5 | validate_certs: no | 5 | validate_certs: no |
6 | headers: | ||
7 | apikey: "{{ kong_app_admin_apikey }}" | ||
6 | register: kong_app_service_plugins_check | 8 | register: kong_app_service_plugins_check |
7 | 9 | ||
8 | - name: Set plugins facts | 10 | - name: Setup plugin |
9 | set_fact: | ||
10 | kong_app_current_plugins: "{{ kong_app_service_plugins_check.json | default('{}') | from_json }}" | ||
11 | |||
12 | - name: Setup plugin {{ plugin.name }} | ||
13 | uri: | 11 | uri: |
14 | url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" | 12 | url: "{{ kong_app_admin_url }}/{{ (current_config.id == '') | ternary('services/' ~ kong_app_service_name ~ '/plugins','plugins/' ~ current_config.id) }}" |
15 | method: "{{ (current_config == {}) | ternary ('POST', 'PATCH') }}" | 13 | method: "{{ (current_config.id == '') | ternary ('POST', 'PATCH') }}" |
16 | body: "{{ plugin | combine(current_body) | to_json }}" | 14 | body: "{{ plugin | combine(current_body) | to_json }}" |
17 | headers: | 15 | headers: |
18 | apikey: "{{ kong_app_admin_apikey }}" | 16 | apikey: "{{ kong_app_admin_apikey }}" |
@@ -22,7 +20,7 @@ | |||
22 | loop_control: | 20 | loop_control: |
23 | loop_var: plugin | 21 | loop_var: plugin |
24 | vars: | 22 | vars: |
25 | current_config: "{{ kong_app_current_plugins.data | selectattr('name', plugin.name) | first |default({}) }}" | 23 | current_config: "{{ kong_app_service_plugins_check.json.data | selectattr('name', 'equalto', plugin.name) | first |default({\"id\": ''}) }}" |
26 | current_id_hash: | 24 | current_id_hash: |
27 | id: "{{ current_config.id | default('')}}" | 25 | id: "{{ current_config.id }}" |
28 | current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}" | 26 | 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 @@ | |||
3 | url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" | 3 | url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" |
4 | method: GET | 4 | method: GET |
5 | validate_certs: no | 5 | validate_certs: no |
6 | headers: | ||
7 | apikey: "{{ kong_app_admin_apikey }}" | ||
6 | register: kong_app_service_routes_check | 8 | register: kong_app_service_routes_check |
7 | 9 | ||
8 | - name: Set routes facts | ||
9 | set_fact: | ||
10 | kong_app_current_routes: "{{ kong_app_service_routes_check.json |default('{\"data\": []}') | from_json }}" | ||
11 | |||
12 | - name: Setup route | 10 | - name: Setup route |
13 | uri: | 11 | uri: |
14 | url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" | 12 | url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" |
@@ -24,9 +22,9 @@ | |||
24 | 22 | ||
25 | - name: Delete old routes | 23 | - name: Delete old routes |
26 | uri: | 24 | uri: |
27 | url: "{{ kong_app_admin_url }}/services/routes/{{ item.id }}" | 25 | url: "{{ kong_app_admin_url }}/routes/{{ item.id }}" |
28 | method: DELETE | 26 | method: DELETE |
29 | headers: | 27 | headers: |
30 | apikey: "{{ kong_app_admin_apikey }}" | 28 | apikey: "{{ kong_app_admin_apikey }}" |
31 | status_code: 204 | 29 | status_code: 204 |
32 | with_items: "{{ kong_app_current_routes.data }}" | 30 | with_items: "{{ kong_app_service_routes_check.json.data }}" |