diff options
author | Gaëtan Duchaussois <gaetan.duchaussois@fretlink.com> | 2019-04-04 16:26:24 +0200 |
---|---|---|
committer | Gaëtan Duchaussois <gaetan.duchaussois@fretlink.com> | 2019-04-04 16:26:24 +0200 |
commit | 082ff4cbc61abd4675158056d1b74317aacb173d (patch) | |
tree | 90d1e38abf9a211a8c7041291567dd167c79ce9c | |
parent | f3304d462d69fbd1466172c3c7cf445eed19f25f (diff) | |
download | ansible-kong-app-082ff4cbc61abd4675158056d1b74317aacb173d.tar.gz ansible-kong-app-082ff4cbc61abd4675158056d1b74317aacb173d.tar.zst ansible-kong-app-082ff4cbc61abd4675158056d1b74317aacb173d.zip |
retry in case of failed patch
-rw-r--r-- | tasks/plugins.yml | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/tasks/plugins.yml b/tasks/plugins.yml index c64e5c9..164f6f2 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml | |||
@@ -9,7 +9,7 @@ | |||
9 | 9 | ||
10 | - name: Setup plugin | 10 | - name: Setup plugin |
11 | uri: | 11 | uri: |
12 | url: "{{ server.kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ service.name ~ '/plugins','plugins/' ~ current_config.id) }}" | 12 | url: "{{ server.kong_app_admin_url }}/{{ exists_plugin | ternary(create_url, update_url) }}" |
13 | method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}" | 13 | method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}" |
14 | body: "{{ plugin | combine(current_body) | to_json }}" | 14 | body: "{{ plugin | combine(current_body) | to_json }}" |
15 | headers: | 15 | headers: |
@@ -20,10 +20,74 @@ | |||
20 | loop_control: | 20 | loop_control: |
21 | loop_var: plugin | 21 | loop_var: plugin |
22 | vars: | 22 | vars: |
23 | current_config: "{{ kong_app_service_plugins_check.json.data | selectattr('name', 'equalto', plugin.name) | first |default({\"id\": ''}) }}" | 23 | create_url: "services/{{ service.name }}/plugins" |
24 | update_url: "plugins/{{ current_config.id }}" | ||
25 | plugins_list: "{{ kong_app_service_plugins_check.json.data }}" | ||
26 | current_config: "{{ plugins_list | selectattr('name', 'equalto', plugin.name) | first |default({\"id\": ''}) }}" | ||
24 | current_id_hash: | 27 | current_id_hash: |
25 | id: "{{ current_config.id }}" | 28 | id: "{{ current_config.id }}" |
26 | current_body: "{{ not current_id_hash.id | ternary({}, current_id_hash) }}" | 29 | current_body: "{{ not current_id_hash.id | ternary({}, current_id_hash) }}" |
27 | exists_plugin: "{{ not current_id_hash.id }}" | 30 | exists_plugin: "{{ not current_id_hash.id }}" |
28 | when: not kong_app_service_plugins_check is skipped | 31 | when: not kong_app_service_plugins_check is skipped |
32 | ignore_errors: true | ||
33 | no_log: true | ||
34 | register: kong_plugin_update_st | ||
35 | |||
36 | - name: Retry failed (deletion) | ||
37 | uri: | ||
38 | url: "{{ url }}" | ||
39 | method: "DELETE" | ||
40 | headers: "{{ headers }}" | ||
41 | status_code: 204 | ||
42 | loop: "{{ kong_plugin_update_st.results }}" | ||
43 | loop_control: | ||
44 | loop_var: result | ||
45 | label: "{{ label_name }}" | ||
46 | vars: | ||
47 | method: "{{ result.invocation.module_args.method }}" | ||
48 | url: "{{ result.invocation.module_args.url }}" | ||
49 | headers: "{{ result.invocation.module_args.headers }}" | ||
50 | label_name: "{{ result.plugin.name }}" | ||
51 | when: | ||
52 | - kong_plugin_update_st is failed | ||
53 | - result is failed | ||
54 | - method == "PATCH" | ||
55 | no_log: true | ||
56 | |||
57 | - name: Retry failed (recreation) | ||
58 | uri: | ||
59 | url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/plugins" | ||
60 | method: "POST" | ||
61 | body: "{{ body }}" | ||
62 | headers: "{{ headers }}" | ||
63 | status_code: 200,201 | ||
64 | loop: "{{ kong_plugin_update_st.results }}" | ||
65 | loop_control: | ||
66 | loop_var: result | ||
67 | label: "{{ label_name }}" | ||
68 | vars: | ||
69 | method: "{{ result.invocation.module_args.method }}" | ||
70 | headers: "{{ result.invocation.module_args.headers }}" | ||
71 | body: "{{ result.invocation.module_args.body }}" | ||
72 | label_name: "{{ result.plugin.name }}" | ||
73 | when: | ||
74 | - kong_plugin_update_st is failed | ||
75 | - result is failed | ||
76 | - method == "PATCH" | ||
77 | no_log: true | ||
78 | |||
79 | - name: Fail otherwise | ||
80 | fail: | ||
81 | msg: "This plugin {{ result.plugin.name }} failed to be created" | ||
82 | loop: "{{ kong_plugin_update_st.results }}" | ||
83 | loop_control: | ||
84 | loop_var: result | ||
85 | label: "{{ label_name }}" | ||
86 | vars: | ||
87 | method: "{{ result.invocation.module_args.method }}" | ||
88 | label_name: "{{ result.plugin.name }}" | ||
89 | when: | ||
90 | - kong_plugin_update_st is failed | ||
91 | - result is failed | ||
92 | - method == "POST" | ||
29 | no_log: true | 93 | no_log: true |