diff options
author | paulrbr-fl <43074087+paulrbr-fl@users.noreply.github.com> | 2020-10-14 10:27:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-14 10:27:09 +0200 |
commit | 9c9fe5d8071afd657e57a6c11f60e275c2261246 (patch) | |
tree | 83eb5c10f9a792a1b5fc8e88a4a1ed675eb13490 /tasks/upstream.yml | |
parent | 2e423637ee780bd273094ad52e49906100724d08 (diff) | |
parent | 1443410095d3b4a2a560997e8a0662a1deed1d57 (diff) | |
download | ansible-kong-app-9c9fe5d8071afd657e57a6c11f60e275c2261246.tar.gz ansible-kong-app-9c9fe5d8071afd657e57a6c11f60e275c2261246.tar.zst ansible-kong-app-9c9fe5d8071afd657e57a6c11f60e275c2261246.zip |
Merge pull request #23 from paulrbr-fl/use-put-for-idempotency
Use PUT methods instead of manually detecting if new or update
Diffstat (limited to 'tasks/upstream.yml')
-rw-r--r-- | tasks/upstream.yml | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/tasks/upstream.yml b/tasks/upstream.yml index 43c1baf..47f2e89 100644 --- a/tasks/upstream.yml +++ b/tasks/upstream.yml | |||
@@ -2,26 +2,16 @@ | |||
2 | set_fact: | 2 | set_fact: |
3 | upstream: "{{ service.upstream }}" | 3 | upstream: "{{ service.upstream }}" |
4 | 4 | ||
5 | - name: Check if upstream exists | 5 | # https://docs.konghq.com/2.1.x/admin-api/#update-or-create-upstream |
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 | 6 | - name: Update or Create upstream |
15 | uri: | 7 | uri: |
16 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ exists_upstream | ternary('', upstream.conf.name) }}" | 8 | url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name) }}" |
17 | method: "{{ exists_upstream | ternary('POST', 'PATCH') }}" | 9 | method: PUT |
18 | body: "{{ upstream.conf | to_json }}" | 10 | body: "{{ upstream.conf | to_json }}" |
19 | status_code: 200,201 | 11 | status_code: 200,201 |
20 | headers: | 12 | headers: |
21 | apikey: "{{ server.kong_app_admin_apikey }}" | 13 | apikey: "{{ server.kong_app_admin_apikey }}" |
22 | Content-Type: application/json | 14 | Content-Type: application/json |
23 | vars: | ||
24 | exists_upstream: "{{ kong_app_check_upstream.status|default(404) == 404 }}" | ||
25 | 15 | ||
26 | - name: Get upstream targets | 16 | - name: Get upstream targets |
27 | uri: | 17 | uri: |