diff options
-rw-r--r-- | README.md | 34 | ||||
-rw-r--r-- | defaults/main.yml | 3 | ||||
-rw-r--r-- | tasks/kong-app.yml | 8 | ||||
-rw-r--r-- | tasks/main.yml | 8 | ||||
-rw-r--r-- | tasks/plugins.yml | 8 | ||||
-rw-r--r-- | tasks/routes.yml | 12 | ||||
-rw-r--r-- | tasks/server.yml | 8 |
7 files changed, 44 insertions, 37 deletions
@@ -10,20 +10,20 @@ None at the moment | |||
10 | 10 | ||
11 | Role Variables | 11 | Role Variables |
12 | -------------- | 12 | -------------- |
13 | 13 | * `kong_servers`: an array of kong\_server to configure with followin configuration: | |
14 | * `kong_app_admin_url` the kong admin url (mandatory). | 14 | * `kong_app_admin_url` the kong admin url (mandatory). |
15 | * `kong_app_admin_apikey` the apikey to use kong admin api. Default to "" | 15 | * `kong_app_admin_apikey` the apikey to use kong admin api. Default to "" |
16 | * `kong_services` an array of services to setup (default to []) | 16 | * `services` an array of services to setup (default to []) |
17 | * `name` the name of the service to create for this app, mandatory | 17 | * `name` the name of the service to create for this app, mandatory |
18 | * `url` the url of the backend of the app, mandatory | 18 | * `url` the url of the backend of the app, mandatory |
19 | * `plugins` An array of plugins to activate with their name and config in a dict | 19 | * `plugins` An array of plugins to activate with their name and config in a dict |
20 | * `name` | 20 | * `name` |
21 | * `config` | 21 | * `config` |
22 | * `routes` An array of routes to create for this service. | 22 | * `routes` An array of routes to create for this service. |
23 | * `hosts` | 23 | * `hosts` |
24 | * `paths` | 24 | * `paths` |
25 | * `protocols` | 25 | * `protocols` |
26 | * `methods` | 26 | * `methods` |
27 | 27 | ||
28 | Dependencies | 28 | Dependencies |
29 | ------------ | 29 | ------------ |
@@ -35,11 +35,11 @@ Example Playbook | |||
35 | 35 | ||
36 | - hosts: localhost | 36 | - hosts: localhost |
37 | roles: | 37 | roles: |
38 | - { role: kong-app, kong_app_admin_url: http://localhost:8001, | 38 | - { role: kong-app, kong_servers: [ kong_app_admin_url: http://localhost:8001, |
39 | kong_app_services: [ name:example, | 39 | services: [ name:example, |
40 | url: http://example.com, | 40 | url: http://example.com, |
41 | plugins: [], | 41 | plugins: [], |
42 | routes: [ { hosts: [my.kong.example], paths: [/] } ]] | 42 | routes: [ { hosts: [my.kong.example], paths: [/] } ]]] |
43 | } | 43 | } |
44 | 44 | ||
45 | License | 45 | License |
diff --git a/defaults/main.yml b/defaults/main.yml index e2de8f5..8962218 100644 --- a/defaults/main.yml +++ b/defaults/main.yml | |||
@@ -1,3 +1,2 @@ | |||
1 | --- | 1 | --- |
2 | kong_app_admin_apikey: "" | 2 | kong_servers: [] |
3 | kong_services: [] | ||
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 @@ | |||
1 | - name: Check if service exists | 1 | - name: Check if service exists |
2 | uri: | 2 | uri: |
3 | url: "{{ kong_app_admin_url }}/services/{{ service.name }}" | 3 | url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}" |
4 | method: GET | 4 | method: GET |
5 | headers: | 5 | headers: |
6 | apikey: "{{ kong_app_admin_apikey }}" | 6 | apikey: "{{ server.kong_app_admin_apikey }}" |
7 | status_code: 200,404 | 7 | status_code: 200,404 |
8 | register: kong_app_check_service | 8 | register: kong_app_check_service |
9 | 9 | ||
10 | - name: Update or Create service | 10 | - name: Update or Create service |
11 | uri: | 11 | uri: |
12 | url: "{{ kong_app_admin_url }}/services/{{ exists_service | ternary('', service.name) }}" | 12 | url: "{{ server.kong_app_admin_url }}/services/{{ exists_service | ternary('', service.name) }}" |
13 | method: "{{ exists_service | ternary('POST', 'PATCH') }}" | 13 | method: "{{ exists_service | ternary('POST', 'PATCH') }}" |
14 | body: "{{ service_body | to_json }}" | 14 | body: "{{ service_body | to_json }}" |
15 | status_code: 200,201 | 15 | status_code: 200,201 |
16 | headers: | 16 | headers: |
17 | apikey: "{{ kong_app_admin_apikey }}" | 17 | apikey: "{{ server.kong_app_admin_apikey }}" |
18 | Content-Type: application/json | 18 | Content-Type: application/json |
19 | vars: | 19 | vars: |
20 | exists_service: "{{ kong_app_check_service.status|default(404) == 404 }}" | 20 | 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 @@ | |||
1 | --- | 1 | --- |
2 | - name: Include kong-app tasks | 2 | - name: Include kong server tasks |
3 | include_tasks: kong-app.yml | 3 | include_tasks: server.yml |
4 | tags: | 4 | tags: |
5 | - kong-app | 5 | - kong-app |
6 | with_items: "{{ kong_services }}" | 6 | with_items: "{{ kong_servers }}" |
7 | loop_control: | 7 | loop_control: |
8 | loop_var: service | 8 | 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 @@ | |||
1 | - name: Get plugins | 1 | - name: Get plugins |
2 | uri: | 2 | uri: |
3 | url: "{{ kong_app_admin_url }}/services/{{ service.name }}/plugins" | 3 | url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/plugins" |
4 | method: GET | 4 | method: GET |
5 | validate_certs: no | 5 | validate_certs: no |
6 | headers: | 6 | headers: |
7 | apikey: "{{ kong_app_admin_apikey }}" | 7 | apikey: "{{ server.kong_app_admin_apikey }}" |
8 | register: kong_app_service_plugins_check | 8 | register: kong_app_service_plugins_check |
9 | 9 | ||
10 | - name: Setup plugin | 10 | - name: Setup plugin |
11 | uri: | 11 | uri: |
12 | url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ service.name ~ '/plugins','plugins/' ~ current_config.id) }}" | 12 | url: "{{ server.kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ service.name ~ '/plugins','plugins/' ~ current_config.id) }}" |
13 | method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}" | 13 | method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}" |
14 | body: "{{ plugin | combine(current_body) | to_json }}" | 14 | body: "{{ plugin | combine(current_body) | to_json }}" |
15 | headers: | 15 | headers: |
16 | apikey: "{{ kong_app_admin_apikey }}" | 16 | apikey: "{{ server.kong_app_admin_apikey }}" |
17 | Content-Type: application/json | 17 | Content-Type: application/json |
18 | status_code: 200,201 | 18 | status_code: 200,201 |
19 | with_items: "{{ service.plugins | default([]) }}" | 19 | 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 @@ | |||
1 | - name: Get app routes | 1 | - name: Get app routes |
2 | uri: | 2 | uri: |
3 | url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes" | 3 | url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/routes" |
4 | method: GET | 4 | method: GET |
5 | validate_certs: no | 5 | validate_certs: no |
6 | headers: | 6 | headers: |
7 | apikey: "{{ kong_app_admin_apikey }}" | 7 | apikey: "{{ server.kong_app_admin_apikey }}" |
8 | register: kong_app_service_routes_check | 8 | register: kong_app_service_routes_check |
9 | 9 | ||
10 | - name: Setup route | 10 | - name: Setup route |
11 | uri: | 11 | uri: |
12 | url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes" | 12 | url: "{{ server.kong_app_admin_url }}/services/{{ service.name }}/routes" |
13 | method: POST | 13 | method: POST |
14 | body: "{{ route | to_json }}" | 14 | body: "{{ route | to_json }}" |
15 | headers: | 15 | headers: |
16 | apikey: "{{ kong_app_admin_apikey }}" | 16 | apikey: "{{ server.kong_app_admin_apikey }}" |
17 | Content-Type: application/json | 17 | Content-Type: application/json |
18 | status_code: 201 | 18 | status_code: 201 |
19 | with_items: "{{ service.routes | default([]) }}" | 19 | with_items: "{{ service.routes | default([]) }}" |
@@ -22,10 +22,10 @@ | |||
22 | 22 | ||
23 | - name: Delete old routes | 23 | - name: Delete old routes |
24 | uri: | 24 | uri: |
25 | url: "{{ kong_app_admin_url }}/routes/{{ item.id }}" | 25 | url: "{{ server.kong_app_admin_url }}/routes/{{ item.id }}" |
26 | method: DELETE | 26 | method: DELETE |
27 | headers: | 27 | headers: |
28 | apikey: "{{ kong_app_admin_apikey }}" | 28 | apikey: "{{ server.kong_app_admin_apikey }}" |
29 | status_code: 204 | 29 | status_code: 204 |
30 | with_items: "{{ kong_app_service_routes_check.json.data }}" | 30 | with_items: "{{ kong_app_service_routes_check.json.data }}" |
31 | when: not kong_app_service_routes_check is skipped | 31 | 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 @@ | |||
1 | --- | ||
2 | - name: Include kong-app tasks | ||
3 | include_tasks: kong-app.yml | ||
4 | tags: | ||
5 | - kong-app | ||
6 | with_items: "{{ server.services }}" | ||
7 | loop_control: | ||
8 | loop_var: service | ||