aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/plugins.yml
blob: e0eee814184c300633af19c8829f39825e3902a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
- name: Get plugins
  uri:
    url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/plugins"
    method: GET
    validate_certs: no
    headers:
      apikey: "{{ server.kong_app_admin_apikey }}"
  register: kong_app_service_plugins_check

- name: debug
  debug:
    var: kong_app_service_plugins_check

- name: debug2
  debug:
    var: current_body
  vars:
    current_config: "{{ kong_app_service_plugins_check.json.data | selectattr('name', 'equalto', plugin.name) | first |default({\"id\": ''}) }}"
    current_id_hash:
      id: "{{ current_config.id }}"
    current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}"
    exists_plugin: "{{ current_id_hash.id == '' }}"
  with_items: "{{ service.plugins | default([]) }}"
  loop_control:
    loop_var: plugin

- name: Setup plugin
  uri:
    url: "{{ server.kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ service.name ~ '/plugins','plugins/' ~ current_config.id) }}"
    method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}"
    body: "{{ plugin | combine(current_body)  | to_json }}"
    headers:
      apikey: "{{ server.kong_app_admin_apikey }}"
      Content-Type: application/json
    status_code: 200,201
  with_items: "{{ service.plugins | default([]) }}"
  loop_control:
    loop_var: plugin
  vars:
    current_config: "{{ kong_app_service_plugins_check.json.data | selectattr('name', 'equalto', plugin.name) | first |default({\"id\": ''}) }}"
    current_id_hash:
      id: "{{ current_config.id }}"
    current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}"
    exists_plugin: "{{ current_id_hash.id == '' }}"
  when: not kong_app_service_plugins_check is skipped
  no_log: false