From 507bb99c0f6c79d5257d293a5eda6bbd3e34caaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Thu, 26 Apr 2018 18:15:47 +0200 Subject: support multiple kong servers --- tasks/kong-app.yml | 8 ++++---- tasks/main.yml | 8 ++++---- tasks/plugins.yml | 8 ++++---- tasks/routes.yml | 12 ++++++------ tasks/server.yml | 8 ++++++++ 5 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 tasks/server.yml (limited to 'tasks') diff --git a/tasks/kong-app.yml b/tasks/kong-app.yml index f94f044..bff2f46 100644 --- a/tasks/kong-app.yml +++ b/tasks/kong-app.yml @@ -1,20 +1,20 @@ - name: Check if service exists uri: - url: "{{ kong_app_admin_url }}/services/{{ service.name }}" + url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}" method: GET headers: - apikey: "{{ kong_app_admin_apikey }}" + apikey: "{{ server.kong_app_admin_apikey }}" status_code: 200,404 register: kong_app_check_service - name: Update or Create service uri: - url: "{{ kong_app_admin_url }}/services/{{ exists_service | ternary('', service.name) }}" + url: "{{ server.kong_app_admin_url }}/services/{{ exists_service | ternary('', service.name) }}" method: "{{ exists_service | ternary('POST', 'PATCH') }}" body: "{{ service_body | to_json }}" status_code: 200,201 headers: - apikey: "{{ kong_app_admin_apikey }}" + apikey: "{{ server.kong_app_admin_apikey }}" Content-Type: application/json vars: exists_service: "{{ kong_app_check_service.status|default(404) == 404 }}" diff --git a/tasks/main.yml b/tasks/main.yml index 4bd42c8..c4e3aec 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,8 @@ --- -- name: Include kong-app tasks - include_tasks: kong-app.yml +- name: Include kong server tasks + include_tasks: server.yml tags: - kong-app - with_items: "{{ kong_services }}" + with_items: "{{ kong_servers }}" loop_control: - loop_var: service + loop_var: server diff --git a/tasks/plugins.yml b/tasks/plugins.yml index 4dd9137..cedbbd2 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -1,19 +1,19 @@ - name: Get plugins uri: - url: "{{ kong_app_admin_url }}/services/{{ service.name }}/plugins" + url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/plugins" method: GET validate_certs: no headers: - apikey: "{{ kong_app_admin_apikey }}" + apikey: "{{ server.kong_app_admin_apikey }}" register: kong_app_service_plugins_check - name: Setup plugin uri: - url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ service.name ~ '/plugins','plugins/' ~ current_config.id) }}" + 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: "{{ kong_app_admin_apikey }}" + apikey: "{{ server.kong_app_admin_apikey }}" Content-Type: application/json status_code: 200,201 with_items: "{{ service.plugins | default([]) }}" diff --git a/tasks/routes.yml b/tasks/routes.yml index 881fc96..3ff2507 100644 --- a/tasks/routes.yml +++ b/tasks/routes.yml @@ -1,19 +1,19 @@ - name: Get app routes uri: - url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes" + url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/routes" method: GET validate_certs: no headers: - apikey: "{{ kong_app_admin_apikey }}" + apikey: "{{ server.kong_app_admin_apikey }}" register: kong_app_service_routes_check - name: Setup route uri: - url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes" + url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/routes" method: POST body: "{{ route | to_json }}" headers: - apikey: "{{ kong_app_admin_apikey }}" + apikey: "{{ server.kong_app_admin_apikey }}" Content-Type: application/json status_code: 201 with_items: "{{ service.routes | default([]) }}" @@ -22,10 +22,10 @@ - name: Delete old routes uri: - url: "{{ kong_app_admin_url }}/routes/{{ item.id }}" + url: "{{ server.kong_app_admin_url }}/routes/{{ item.id }}" method: DELETE headers: - apikey: "{{ kong_app_admin_apikey }}" + apikey: "{{ server.kong_app_admin_apikey }}" status_code: 204 with_items: "{{ kong_app_service_routes_check.json.data }}" when: not kong_app_service_routes_check is skipped diff --git a/tasks/server.yml b/tasks/server.yml new file mode 100644 index 0000000..664fb99 --- /dev/null +++ b/tasks/server.yml @@ -0,0 +1,8 @@ +--- +- name: Include kong-app tasks + include_tasks: kong-app.yml + tags: + - kong-app + with_items: "{{ server.services }}" + loop_control: + loop_var: service -- cgit v1.2.3