diff options
author | Gaëtan Duchaussois <gaetan.duchaussois@fretlink.com> | 2018-05-14 16:22:00 +0200 |
---|---|---|
committer | Gaëtan Duchaussois <gaetan.duchaussois@fretlink.com> | 2018-05-14 16:22:00 +0200 |
commit | fb5b452707a004967d7b27abc5d515a03278d446 (patch) | |
tree | c3e524077759cc2acb6d33bfb320a35c73f17a1f /tasks | |
parent | 03d5555b42e25dd6da9a0241e8a5f5937a9bbeb8 (diff) | |
download | ansible-kong-app-fb5b452707a004967d7b27abc5d515a03278d446.tar.gz ansible-kong-app-fb5b452707a004967d7b27abc5d515a03278d446.tar.zst ansible-kong-app-fb5b452707a004967d7b27abc5d515a03278d446.zip |
add support for upstream with multiple targets
Diffstat (limited to 'tasks')
-rw-r--r-- | tasks/kong-app.yml | 4 | ||||
-rw-r--r-- | tasks/upstream.yml | 55 |
2 files changed, 59 insertions, 0 deletions
diff --git a/tasks/kong-app.yml b/tasks/kong-app.yml index bff2f46..975e2cd 100644 --- a/tasks/kong-app.yml +++ b/tasks/kong-app.yml | |||
@@ -1,3 +1,7 @@ | |||
1 | - name: Upstream Creation | ||
2 | import_tasks: upstream.yml | ||
3 | when: service.upstream is defined | ||
4 | |||
1 | - name: Check if service exists | 5 | - name: Check if service exists |
2 | uri: | 6 | uri: |
3 | url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}" | 7 | url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}" |
diff --git a/tasks/upstream.yml b/tasks/upstream.yml new file mode 100644 index 0000000..e944c82 --- /dev/null +++ b/tasks/upstream.yml | |||
@@ -0,0 +1,55 @@ | |||
1 | - name: Set upstream variable | ||
2 | set_fact: | ||
3 | upstream: "{{ service.upstream }}" | ||
4 | |||
5 | - name: Check if upstream exists | ||
6 | uri: | ||
7 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}" | ||
8 | method: GET | ||
9 | headers: | ||
10 | apikey: "{{ server.kong_app_admin_apikey }}" | ||
11 | status_code: 200,404 | ||
12 | register: kong_app_check_upstream | ||
13 | |||
14 | - name: Update or Create upstream | ||
15 | uri: | ||
16 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ exists_upstream | ternary('', upstream.conf.name) }}" | ||
17 | method: "{{ exists_upstream | ternary('POST', 'PATCH') }}" | ||
18 | body: "{{ upstream.conf | to_json }}" | ||
19 | status_code: 200,201 | ||
20 | headers: | ||
21 | apikey: "{{ server.kong_app_admin_apikey }}" | ||
22 | Content-Type: application/json | ||
23 | vars: | ||
24 | exists_upstream: "{{ kong_app_check_upstream.status|default(404) == 404 }}" | ||
25 | |||
26 | - name: Get upstream targets | ||
27 | uri: | ||
28 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets" | ||
29 | method: GET | ||
30 | headers: | ||
31 | apikey: "{{ server.kong_app_admin_apikey }}" | ||
32 | register: kong_app_service_targets_check | ||
33 | |||
34 | - name: Create targets | ||
35 | uri: | ||
36 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets" | ||
37 | method: POST | ||
38 | body: "{{ target | to_json }}" | ||
39 | headers: | ||
40 | apikey: "{{ server.kong_app_admin_apikey }}" | ||
41 | Content-Type: application/json | ||
42 | status_code: 201 | ||
43 | with_items: "{{ upstream.targets | default([]) }}" | ||
44 | loop_control: | ||
45 | loop_var: target | ||
46 | |||
47 | - name: Delete old targets | ||
48 | uri: | ||
49 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets/{{ item.id }}" | ||
50 | method: DELETE | ||
51 | headers: | ||
52 | apikey: "{{ server.kong_app_admin_apikey }}" | ||
53 | status_code: 204 | ||
54 | with_items: "{{ kong_app_service_targets_check.json.data }}" | ||
55 | when: not kong_app_service_targets_check is skipped | ||