]>
Commit | Line | Data |
---|---|---|
1 | - name: Set upstream variable | |
2 | set_fact: | |
3 | upstream: "{{ service.upstream }}" | |
4 | ||
5 | # https://docs.konghq.com/2.1.x/admin-api/#update-or-create-upstream | |
6 | - name: Update or Create upstream | |
7 | uri: | |
8 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name) }}" | |
9 | method: PUT | |
10 | body: "{{ upstream.conf | to_json }}" | |
11 | status_code: 200,201 | |
12 | headers: | |
13 | apikey: "{{ server.kong_app_admin_apikey }}" | |
14 | Content-Type: application/json | |
15 | ||
16 | - name: Get upstream targets | |
17 | uri: | |
18 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets" | |
19 | method: GET | |
20 | headers: | |
21 | apikey: "{{ server.kong_app_admin_apikey }}" | |
22 | register: kong_app_service_targets_check | |
23 | ||
24 | - name: Create targets | |
25 | uri: | |
26 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets" | |
27 | method: POST | |
28 | body: "{{ target | to_json }}" | |
29 | headers: | |
30 | apikey: "{{ server.kong_app_admin_apikey }}" | |
31 | Content-Type: application/json | |
32 | status_code: 200,201 | |
33 | with_items: "{{ upstream.targets | default([]) }}" | |
34 | loop_control: | |
35 | loop_var: target | |
36 | ||
37 | - name: Delete old targets | |
38 | uri: | |
39 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets/{{ item.id }}" | |
40 | method: DELETE | |
41 | headers: | |
42 | apikey: "{{ server.kong_app_admin_apikey }}" | |
43 | status_code: 204,404 | |
44 | with_items: "{{ kong_app_service_targets_check.json.data }}" | |
45 | when: not kong_app_service_targets_check is skipped |