diff options
Diffstat (limited to 'tasks/upstream.yml')
-rw-r--r-- | tasks/upstream.yml | 55 |
1 files changed, 55 insertions, 0 deletions
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 | ||