aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>2018-04-20 10:04:41 +0200
committerGaëtan Duchaussois <gaetan.duchaussois@fretlink.com>2018-04-20 10:04:41 +0200
commit1a33ca3184dbea838ea083a7cf026cf5884dc3f4 (patch)
treec097cc0071eb765584897f1da6487702893ad6f8
parent530dddec969df385e9aa29af0917f6ca97094d68 (diff)
downloadansible-kong-app-1a33ca3184dbea838ea083a7cf026cf5884dc3f4.tar.gz
ansible-kong-app-1a33ca3184dbea838ea083a7cf026cf5884dc3f4.tar.zst
ansible-kong-app-1a33ca3184dbea838ea083a7cf026cf5884dc3f4.zip
initial version
-rw-r--r--ansible.cfg2
-rw-r--r--defaults/main.yml4
-rw-r--r--handlers/main.yml2
-rw-r--r--meta/main.yml57
-rw-r--r--tasks/kong-app.yml24
-rw-r--r--tasks/main.yml5
-rw-r--r--tasks/plugins.yml28
-rw-r--r--tasks/routes.yml32
-rw-r--r--tests/inventory2
-rw-r--r--tests/test.retry1
-rw-r--r--tests/test.yml8
-rw-r--r--vars/main.yml4
12 files changed, 169 insertions, 0 deletions
diff --git a/ansible.cfg b/ansible.cfg
new file mode 100644
index 0000000..6462621
--- /dev/null
+++ b/ansible.cfg
@@ -0,0 +1,2 @@
1[defaults]
2roles_path=../
diff --git a/defaults/main.yml b/defaults/main.yml
new file mode 100644
index 0000000..d75773b
--- /dev/null
+++ b/defaults/main.yml
@@ -0,0 +1,4 @@
1---
2kong_app_admin_apikey: ""
3kong_app_plugins: []
4kong_app_routes: []
diff --git a/handlers/main.yml b/handlers/main.yml
new file mode 100644
index 0000000..fd808d4
--- /dev/null
+++ b/handlers/main.yml
@@ -0,0 +1,2 @@
1---
2# handlers file for ansible-kong-app \ No newline at end of file
diff --git a/meta/main.yml b/meta/main.yml
new file mode 100644
index 0000000..e2b8be4
--- /dev/null
+++ b/meta/main.yml
@@ -0,0 +1,57 @@
1galaxy_info:
2 author: FretLink team
3 description: Love and trucks
4 company: FretLink
5
6 # If the issue tracker for your role is not on github, uncomment the
7 # next line and provide a value
8 # issue_tracker_url: http://example.com/issue/tracker
9
10 # Some suggested licenses:
11 # - BSD (default)
12 # - MIT
13 # - GPLv2
14 # - GPLv3
15 # - Apache
16 # - CC-BY
17 license: TBD
18
19 min_ansible_version: 2.4
20
21 # If this a Container Enabled role, provide the minimum Ansible Container version.
22 # min_ansible_container_version:
23
24 # Optionally specify the branch Galaxy will use when accessing the GitHub
25 # repo for this role. During role install, if no tags are available,
26 # Galaxy will use this branch. During import Galaxy will access files on
27 # this branch. If Travis integration is configured, only notifications for this
28 # branch will be accepted. Otherwise, in all cases, the repo's default branch
29 # (usually master) will be used.
30 #github_branch:
31
32 #
33 # platforms is a list of platforms, and each platform has a name and a list of versions.
34 #
35 # platforms:
36 # - name: Fedora
37 # versions:
38 # - all
39 # - 25
40 # - name: SomePlatform
41 # versions:
42 # - all
43 # - 1.0
44 # - 7
45 # - 99.99
46
47 galaxy_tags: []
48 # List tags for your role here, one per line. A tag is a keyword that describes
49 # and categorizes the role. Users find roles by searching for tags. Be sure to
50 # remove the '[]' above, if you add tags to this list.
51 #
52 # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
53 # Maximum 20 tags per role.
54
55dependencies: []
56 # List your role dependencies here, one per line. Be sure to remove the '[]' above,
57 # if you add dependencies to this list.
diff --git a/tasks/kong-app.yml b/tasks/kong-app.yml
new file mode 100644
index 0000000..d50c193
--- /dev/null
+++ b/tasks/kong-app.yml
@@ -0,0 +1,24 @@
1- name: Check if service exists
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}"
4 method: GET
5 headers:
6 apikey: "{{ kong_app_admin_apikey }}"
7 status_code: 200,404
8 register: kong_app_check_service
9
10#- name: Update or Create service
11# uri:
12# url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}"
13# method: "{{ (kong_app_check_service.status_code == 404) | ternary ('POST', 'PATCH') }}"
14# body: "{{ kong_app_service_body | to_json }}"
15# headers:
16# apikey: "{{ kong_app_admin_apikey }}"
17# Content-Type: application/json
18# status_code: 200,201
19
20- name: Setup plugins
21 import_tasks: plugins.yml
22
23- name: Setup routes
24 import_tasks: routes.yml
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..4bb562f
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,5 @@
1---
2- name: Include kong-app tasks
3 import_tasks: kong-app.yml
4 tags:
5 - kong-app
diff --git a/tasks/plugins.yml b/tasks/plugins.yml
new file mode 100644
index 0000000..c8f165c
--- /dev/null
+++ b/tasks/plugins.yml
@@ -0,0 +1,28 @@
1- name: Get plugins
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins"
4 method: GET
5 validate_certs: no
6 register: kong_app_service_plugins_check
7
8- name: Set plugins facts
9 set_fact:
10 kong_app_current_plugins: "{{ kong_app_service_plugins_check.json | default('{}') | from_json }}"
11
12- name: Setup plugin {{ plugin.name }}
13 uri:
14 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins"
15 method: "{{ (current_config == {}) | ternary ('POST', 'PATCH') }}"
16 body: "{{ plugin | combine(current_body) | to_json }}"
17 headers:
18 apikey: "{{ kong_app_admin_apikey }}"
19 Content-Type: application/json
20 status_code: 200,201
21 with_items: "{{ kong_app_plugins }}"
22 loop_control:
23 loop_var: plugin
24 vars:
25 current_config: "{{ kong_app_current_plugins.data | selectattr('name', plugin.name) | first |default({}) }}"
26 current_id_hash:
27 id: "{{ current_config.id | default('')}}"
28 current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}"
diff --git a/tasks/routes.yml b/tasks/routes.yml
new file mode 100644
index 0000000..1a9f6db
--- /dev/null
+++ b/tasks/routes.yml
@@ -0,0 +1,32 @@
1- name: Get app routes
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes"
4 method: GET
5 validate_certs: no
6 register: kong_app_service_routes_check
7
8- name: Set routes facts
9 set_fact:
10 kong_app_current_routes: "{{ kong_app_service_routes_check.json |default('{\"data\": []}') | from_json }}"
11
12- name: Setup route
13 uri:
14 url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes"
15 method: POST
16 body: "{{ route | to_json }}"
17 headers:
18 apikey: "{{ kong_app_admin_apikey }}"
19 Content-Type: application/json
20 status_code: 201
21 with_items: "{{ kong_app_routes }}"
22 loop_control:
23 loop_var: route
24
25- name: Delete old routes
26 uri:
27 url: "{{ kong_app_admin_url }}/services/routes/{{ item.id }}"
28 method: DELETE
29 headers:
30 apikey: "{{ kong_app_admin_apikey }}"
31 status_code: 204
32 with_items: "{{ kong_app_current_routes.data }}"
diff --git a/tests/inventory b/tests/inventory
new file mode 100644
index 0000000..878877b
--- /dev/null
+++ b/tests/inventory
@@ -0,0 +1,2 @@
1localhost
2
diff --git a/tests/test.retry b/tests/test.retry
new file mode 100644
index 0000000..2fbb50c
--- /dev/null
+++ b/tests/test.retry
@@ -0,0 +1 @@
localhost
diff --git a/tests/test.yml b/tests/test.yml
new file mode 100644
index 0000000..fb0d9b8
--- /dev/null
+++ b/tests/test.yml
@@ -0,0 +1,8 @@
1---
2- hosts: localhost
3 remote_user: root
4 roles:
5 - role: ansible-kong-app
6 kong_app_admin_url: http://127.0.0.1:8000
7 kong_app_service_name: toto
8 kong_app_service_url: http://example.com
diff --git a/vars/main.yml b/vars/main.yml
new file mode 100644
index 0000000..02f5cd6
--- /dev/null
+++ b/vars/main.yml
@@ -0,0 +1,4 @@
1---
2kong_app_service_body:
3 name: "{{ kong_app_service_name }}"
4 url: "{{ kong_app_service_url }}"