]> git.immae.eu Git - github/fretlink/ansible-kong-app.git/commitdiff
support multiple kong servers
authorGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>
Thu, 26 Apr 2018 16:15:47 +0000 (18:15 +0200)
committerGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>
Thu, 26 Apr 2018 16:39:08 +0000 (18:39 +0200)
README.md
defaults/main.yml
tasks/kong-app.yml
tasks/main.yml
tasks/plugins.yml
tasks/routes.yml
tasks/server.yml [new file with mode: 0644]

index 074e830e9a890dff39e2fba4a4c1905c309ac542..e9a2a29610225e3127a94cb93bbeb12f77250046 100644 (file)
--- a/README.md
+++ b/README.md
@@ -10,20 +10,20 @@ None at the moment
 
 Role Variables
 --------------
-
-* `kong_app_admin_url` the kong admin url (mandatory).
-* `kong_app_admin_apikey` the apikey to use kong admin api. Default to ""
-* `kong_services` an array of services to setup (default to [])
-  * `name` the name of the service to create for this app, mandatory
-  * `url` the url of the backend of the app, mandatory
-  * `plugins` An array of plugins to activate with their name and config in a dict
-    * `name`
-    * `config`
-  * `routes` An array of routes to create for this service.
-    * `hosts`
-    * `paths`
-    * `protocols`
-    * `methods`
+* `kong_servers`: an array of kong\_server to configure with followin configuration:
+  * `kong_app_admin_url` the kong admin url (mandatory).
+  * `kong_app_admin_apikey` the apikey to use kong admin api. Default to ""
+  * `kong_services` an array of services to setup (default to [])
+    * `name` the name of the service to create for this app, mandatory
+    * `url` the url of the backend of the app, mandatory
+    * `plugins` An array of plugins to activate with their name and config in a dict
+      * `name`
+      * `config`
+    * `routes` An array of routes to create for this service.
+      * `hosts`
+      * `paths`
+      * `protocols`
+      * `methods`
 
 Dependencies
 ------------
index e2de8f544d0ae917c132fff68e52246c429c3eac..8962218d7554b822968678fd84e05038baa99282 100644 (file)
@@ -1,3 +1,2 @@
 ---
-kong_app_admin_apikey: ""
-kong_services: []
+kong_servers: []
index f94f0446b7b9e942090cbb345b4bfd1a02619cb6..bff2f46dc06658d05f71c7a43f5a9a0e0595ba9f 100644 (file)
@@ -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 }}"
index 4bd42c81023d272f7794f45bd06791904cb00194..c4e3aec3e018c0c2176f11348d077a0728644337 100644 (file)
@@ -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
index 4dd91372ac9c8a3ed412f3d96b318991d6aec464..cedbbd2af2b089dcf0cc8457118b194ea4731aa0 100644 (file)
@@ -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([]) }}"
index 881fc9626656df4a92b020a97fdd11a88500beea..3ff25077350a740d658855483e21894e50e50044 100644 (file)
@@ -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([]) }}"
 
 - 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 (file)
index 0000000..664fb99
--- /dev/null
@@ -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