]> git.immae.eu Git - github/fretlink/ansible-kong-app.git/commitdiff
setup an array of services 1/head
authorGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>
Mon, 23 Apr 2018 08:35:56 +0000 (10:35 +0200)
committerGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>
Mon, 23 Apr 2018 08:41:27 +0000 (10:41 +0200)
README.md
defaults/main.yml
tasks/kong-app.yml
tasks/main.yml
tasks/plugins.yml
tasks/routes.yml
tests/test.retry [deleted file]
vars/main.yml

index 5cf5f186a40c146880ee88b57a071d81379d9471..074e830e9a890dff39e2fba4a4c1905c309ac542 100644 (file)
--- a/README.md
+++ b/README.md
@@ -13,16 +13,17 @@ 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_app_service_name` the nameof the service to create for this app, mandatory
-* `kong_app_service_url` the url of the backend of the app, mandatory
-* `kong_app_plugins` An array of plugins to activate with their name and config in a dict
-  * `name`
-  * `config`
-* `kong_app_routes` An array of routes to create for this app.
-  * `hosts`
-  * `paths`
-  * `protocols`
-  * `methods`
+* `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
 ------------
@@ -35,10 +36,10 @@ Example Playbook
     - hosts: localhost
       roles:
          - { role: kong-app, kong_app_admin_url: http://localhost:8001,
-             kong_app_service_name: example,
-             kong_app_service_url: http://example.com,
-             kong_app_plugins: [],
-             kong_app_routes: [ { hosts: [my.kong.example], paths: [/] } ]
+             kong_app_services: [ name:example,
+             url: http://example.com,
+             plugins: [],
+             routes: [ { hosts: [my.kong.example], paths: [/] } ]]
            }
 
 License
index d75773b249fc8d7e34edbf85dc808f11911f5513..e2de8f544d0ae917c132fff68e52246c429c3eac 100644 (file)
@@ -1,4 +1,3 @@
 ---
 kong_app_admin_apikey: ""
-kong_app_plugins: []
-kong_app_routes: []
+kong_services: []
index df95f2ec27a1633d84d042dafa12b36ce762345e..f94f0446b7b9e942090cbb345b4bfd1a02619cb6 100644 (file)
@@ -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
index 4bb562fb4037f05a54ce26bdad3ee73db82fc1a9..4bd42c81023d272f7794f45bd06791904cb00194 100644 (file)
@@ -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
index f096d4b717ff0c8cfafb1f60e5ec7af606d1d7ab..3ae0fbefd29bbe539df6d8dd167cc4b8a1e27123 100644 (file)
@@ -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:
index 4581e8c131e3cccf6db45beab0d1092e015893f7..881fc9626656df4a92b020a97fdd11a88500beea 100644 (file)
@@ -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
 
diff --git a/tests/test.retry b/tests/test.retry
deleted file mode 100644 (file)
index 2fbb50c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-localhost
index 02f5cd601af061e10187b58d23fed2ceb5f0c565..ed97d539c095cf1413af30cc23dea272095b97dd 100644 (file)
@@ -1,4 +1 @@
 ---
-kong_app_service_body:
-  name: "{{ kong_app_service_name }}"
-  url: "{{ kong_app_service_url }}"