]> git.immae.eu Git - github/fretlink/ansible-kong-app.git/blame - tasks/plugins.yml
Add info on failures
[github/fretlink/ansible-kong-app.git] / tasks / plugins.yml
CommitLineData
1a33ca31
GD
1- name: Get plugins
2 uri:
507bb99c 3 url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/plugins"
1a33ca31
GD
4 method: GET
5 validate_certs: no
ad5e125a 6 headers:
507bb99c 7 apikey: "{{ server.kong_app_admin_apikey }}"
1a33ca31
GD
8 register: kong_app_service_plugins_check
9
ad5e125a 10- name: Setup plugin
1a33ca31 11 uri:
082ff4cb 12 url: "{{ server.kong_app_admin_url }}/{{ exists_plugin | ternary(create_url, update_url) }}"
d213edd1 13 method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}"
1a33ca31
GD
14 body: "{{ plugin | combine(current_body) | to_json }}"
15 headers:
507bb99c 16 apikey: "{{ server.kong_app_admin_apikey }}"
1a33ca31
GD
17 Content-Type: application/json
18 status_code: 200,201
767c0e53 19 with_items: "{{ service.plugins | default([]) }}"
1a33ca31
GD
20 loop_control:
21 loop_var: plugin
22 vars:
082ff4cb
GD
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\": ''}) }}"
1a33ca31 27 current_id_hash:
ad5e125a 28 id: "{{ current_config.id }}"
03c60382 29 current_body: "{{ (not current_id_hash.id) | ternary({}, current_id_hash) }}"
00cd8173 30 exists_plugin: "{{ not current_id_hash.id }}"
0682b865 31 when: not kong_app_service_plugins_check is skipped
082ff4cb
GD
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"
03c60382 61 body: "{{ body | to_json }}"
082ff4cb
GD
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
df1e3339
GD
79- name: Give info on errors
80 debug:
81 msg: "{{ info }}"
82 loop: "{{ kong_plugin_update_st.results }}"
83 loop_control:
84 label: "{{ item.plugin.name }}"
85 when:
86 - kong_plugin_update_st is failed
87 - item is failed
88 - item.plugin is defined
89 - item.plugin.name is defined
90 - item.json is defined
91 - item.json.message is defined
92 vars:
93 info: "{{ item.json.message }}"
94
082ff4cb
GD
95- name: Fail otherwise
96 fail:
97 msg: "This plugin {{ result.plugin.name }} failed to be created"
98 loop: "{{ kong_plugin_update_st.results }}"
99 loop_control:
100 loop_var: result
101 label: "{{ label_name }}"
102 vars:
103 method: "{{ result.invocation.module_args.method }}"
104 label_name: "{{ result.plugin.name }}"
105 when:
106 - kong_plugin_update_st is failed
107 - result is failed
108 - method == "POST"
7f2aabcb 109 no_log: true