From 767c0e538b6b7c751784444fd6c676668e3a1b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Mon, 23 Apr 2018 10:35:56 +0200 Subject: setup an array of services --- tasks/kong-app.yml | 9 ++++++--- tasks/main.yml | 5 ++++- tasks/plugins.yml | 6 +++--- tasks/routes.yml | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) (limited to 'tasks') diff --git a/tasks/kong-app.yml b/tasks/kong-app.yml index df95f2e..f94f044 100644 --- a/tasks/kong-app.yml +++ b/tasks/kong-app.yml @@ -1,6 +1,6 @@ - name: Check if service exists uri: - url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}" + url: "{{ kong_app_admin_url }}/services/{{ service.name }}" method: GET headers: apikey: "{{ kong_app_admin_apikey }}" @@ -9,15 +9,18 @@ - name: Update or Create service uri: - url: "{{ kong_app_admin_url }}/services/{{ exists_service | ternary('', kong_app_service_name) }}" + url: "{{ kong_app_admin_url }}/services/{{ exists_service | ternary('', service.name) }}" method: "{{ exists_service | ternary('POST', 'PATCH') }}" - body: "{{ kong_app_service_body | to_json }}" + body: "{{ service_body | to_json }}" status_code: 200,201 headers: apikey: "{{ kong_app_admin_apikey }}" Content-Type: application/json vars: exists_service: "{{ kong_app_check_service.status|default(404) == 404 }}" + service_body: + name: "{{ service.name }}" + url: "{{ service.url }}" - name: Setup plugins import_tasks: plugins.yml diff --git a/tasks/main.yml b/tasks/main.yml index 4bb562f..4bd42c8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,8 @@ --- - name: Include kong-app tasks - import_tasks: kong-app.yml + include_tasks: kong-app.yml tags: - kong-app + with_items: "{{ kong_services }}" + loop_control: + loop_var: service diff --git a/tasks/plugins.yml b/tasks/plugins.yml index f096d4b..3ae0fbe 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -1,6 +1,6 @@ - name: Get plugins uri: - url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins" + url: "{{ kong_app_admin_url }}/services/{{ service.name }}/plugins" method: GET validate_certs: no headers: @@ -9,14 +9,14 @@ - name: Setup plugin uri: - url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ kong_app_service_name ~ '/plugins','plugins/' ~ current_config.id) }}" + url: "{{ 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 }}" Content-Type: application/json status_code: 200,201 - with_items: "{{ kong_app_plugins }}" + with_items: "{{ service.plugins | default([]) }}" loop_control: loop_var: plugin vars: diff --git a/tasks/routes.yml b/tasks/routes.yml index 4581e8c..881fc96 100644 --- a/tasks/routes.yml +++ b/tasks/routes.yml @@ -1,6 +1,6 @@ - name: Get app routes uri: - url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" + url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes" method: GET validate_certs: no headers: @@ -9,14 +9,14 @@ - name: Setup route uri: - url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes" + url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes" method: POST body: "{{ route | to_json }}" headers: apikey: "{{ kong_app_admin_apikey }}" Content-Type: application/json status_code: 201 - with_items: "{{ kong_app_routes }}" + with_items: "{{ service.routes | default([]) }}" loop_control: loop_var: route -- cgit v1.2.3