aboutsummaryrefslogblamecommitdiffhomepage
path: root/tasks/upstream.yml
blob: 6aab61709af56fc882356cfc6769205db8e62a01 (plain) (tree)
1
2
3
4
5
6
7
8
9



                                      
                                                                    

                                 

                                                                              




                                                  
















                                                                                     
                        









                                                                                                   
                        

                                                              
- name: Set upstream variable
  set_fact:
    upstream: "{{ service.upstream }}"

# https://docs.konghq.com/2.1.x/admin-api/#update-or-create-upstream
- name: Update or Create upstream
  uri:
    url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name) }}"
    method: PUT
    body: "{{ upstream.conf | to_json }}"
    status_code: 200,201
    headers:
      apikey: "{{ server.kong_app_admin_apikey }}"
      Content-Type: application/json

- name: Get upstream targets
  uri:
    url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets"
    method: GET
    headers:
      apikey: "{{ server.kong_app_admin_apikey }}"
  register: kong_app_service_targets_check

- name: Create targets
  uri:
    url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets"
    method: POST
    body: "{{ target | to_json }}"
    headers:
      apikey: "{{ server.kong_app_admin_apikey }}"
      Content-Type: application/json
    status_code: 200,201
  with_items: "{{ upstream.targets | default([]) }}"
  loop_control:
    loop_var: target

- name: Delete old targets
  uri:
    url: "{{ server.kong_app_admin_url }}/upstreams/{{ upstream.conf.name }}/targets/{{ item.id }}"
    method: DELETE
    headers:
      apikey: "{{ server.kong_app_admin_apikey }}"
    status_code: 204,404
  with_items: "{{ kong_app_service_targets_check.json.data }}"
  when: not kong_app_service_targets_check is skipped