aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGaƫtan <36162164+gaetanfl@users.noreply.github.com>2018-04-23 10:57:50 +0200
committerGitHub <noreply@github.com>2018-04-23 10:57:50 +0200
commit208d503983ba44c64f92c20e8d062905a2ac47f5 (patch)
tree6708c8474e2a2749f737817840b0f050d5236e44
parent530dddec969df385e9aa29af0917f6ca97094d68 (diff)
parent767c0e538b6b7c751784444fd6c676668e3a1b01 (diff)
downloadansible-kong-app-0.1.tar.gz
ansible-kong-app-0.1.tar.zst
ansible-kong-app-0.1.zip
Merge pull request #1 from gaetanfl/initial_versionv0.1
initial version
-rw-r--r--.travis.yml32
-rw-r--r--README.md29
-rw-r--r--ansible.cfg2
-rw-r--r--defaults/main.yml3
-rw-r--r--handlers/main.yml2
-rw-r--r--meta/main.yml57
-rw-r--r--tasks/kong-app.yml29
-rw-r--r--tasks/main.yml8
-rw-r--r--tasks/plugins.yml28
-rw-r--r--tasks/routes.yml31
-rw-r--r--tests/inventory2
-rw-r--r--tests/test.yml8
-rw-r--r--vars/main.yml1
13 files changed, 218 insertions, 14 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..812d0fe
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,32 @@
1---
2language: python
3python: "2.7"
4
5# Use the new container infrastructure
6sudo: false
7
8# Install ansible
9addons:
10 apt:
11 packages:
12 - python-pip
13
14install:
15 # Install ansible
16 - pip install ansible
17 - pip install ansible-lint
18
19 # Check ansible version
20 - ansible --version
21
22 # Create ansible.cfg with correct roles_path
23 - printf '[defaults]\nroles_path=../' >ansible.cfg
24
25script:
26 # Basic role syntax check
27 - ansible-playbook tests/test.yml -i tests/inventory --syntax-check
28 - ansible-lint .
29 - ansible-playbook tests/test.yml -i tests/inventory -C -D
30
31notifications:
32 webhooks: https://galaxy.ansible.com/api/v1/notifications/
diff --git a/README.md b/README.md
index 5cf5f18..074e830 100644
--- a/README.md
+++ b/README.md
@@ -13,16 +13,17 @@ Role Variables
13 13
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_app_service_name` the nameof the service to create for this app, mandatory 16* `kong_services` an array of services to setup (default to [])
17* `kong_app_service_url` the url of the backend of the app, mandatory 17 * `name` the name of the service to create for this app, mandatory
18* `kong_app_plugins` An array of plugins to activate with their name and config in a dict 18 * `url` the url of the backend of the app, mandatory
19 * `name` 19 * `plugins` An array of plugins to activate with their name and config in a dict
20 * `config` 20 * `name`
21* `kong_app_routes` An array of routes to create for this app. 21 * `config`
22 * `hosts` 22 * `routes` An array of routes to create for this service.
23 * `paths` 23 * `hosts`
24 * `protocols` 24 * `paths`
25 * `methods` 25 * `protocols`
26 * `methods`
26 27
27Dependencies 28Dependencies
28------------ 29------------
@@ -35,10 +36,10 @@ Example Playbook
35 - hosts: localhost 36 - hosts: localhost
36 roles: 37 roles:
37 - { role: kong-app, kong_app_admin_url: http://localhost:8001, 38 - { role: kong-app, kong_app_admin_url: http://localhost:8001,
38 kong_app_service_name: example, 39 kong_app_services: [ name:example,
39 kong_app_service_url: http://example.com, 40 url: http://example.com,
40 kong_app_plugins: [], 41 plugins: [],
41 kong_app_routes: [ { hosts: [my.kong.example], paths: [/] } ] 42 routes: [ { hosts: [my.kong.example], paths: [/] } ]]
42 } 43 }
43 44
44License 45License
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..e2de8f5
--- /dev/null
+++ b/defaults/main.yml
@@ -0,0 +1,3 @@
1---
2kong_app_admin_apikey: ""
3kong_services: []
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..a2ae975
--- /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..f94f044
--- /dev/null
+++ b/tasks/kong-app.yml
@@ -0,0 +1,29 @@
1- name: Check if service exists
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ 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/{{ exists_service | ternary('', service.name) }}"
13 method: "{{ exists_service | ternary('POST', 'PATCH') }}"
14 body: "{{ service_body | to_json }}"
15 status_code: 200,201
16 headers:
17 apikey: "{{ kong_app_admin_apikey }}"
18 Content-Type: application/json
19 vars:
20 exists_service: "{{ kong_app_check_service.status|default(404) == 404 }}"
21 service_body:
22 name: "{{ service.name }}"
23 url: "{{ service.url }}"
24
25- name: Setup plugins
26 import_tasks: plugins.yml
27
28- name: Setup routes
29 import_tasks: routes.yml
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..4bd42c8
--- /dev/null
+++ b/tasks/main.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: "{{ kong_services }}"
7 loop_control:
8 loop_var: service
diff --git a/tasks/plugins.yml b/tasks/plugins.yml
new file mode 100644
index 0000000..3ae0fbe
--- /dev/null
+++ b/tasks/plugins.yml
@@ -0,0 +1,28 @@
1- name: Get plugins
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/plugins"
4 method: GET
5 validate_certs: no
6 headers:
7 apikey: "{{ kong_app_admin_apikey }}"
8 register: kong_app_service_plugins_check
9
10- name: Setup plugin
11 uri:
12 url: "{{ kong_app_admin_url }}/{{ exists_plugin | ternary('services/' ~ service.name ~ '/plugins','plugins/' ~ current_config.id) }}"
13 method: "{{ exists_plugin | ternary ('POST', 'PATCH') }}"
14 body: "{{ plugin | combine(current_body) | to_json }}"
15 headers:
16 apikey: "{{ kong_app_admin_apikey }}"
17 Content-Type: application/json
18 status_code: 200,201
19 with_items: "{{ service.plugins | default([]) }}"
20 loop_control:
21 loop_var: plugin
22 vars:
23 current_config: "{{ kong_app_service_plugins_check.json.data | selectattr('name', 'equalto', plugin.name) | first |default({\"id\": ''}) }}"
24 current_id_hash:
25 id: "{{ current_config.id }}"
26 current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}"
27 exists_plugin: "{{ current_id_hash.id == '' }}"
28 when: not kong_app_service_plugins_check is skipped
diff --git a/tasks/routes.yml b/tasks/routes.yml
new file mode 100644
index 0000000..881fc96
--- /dev/null
+++ b/tasks/routes.yml
@@ -0,0 +1,31 @@
1- name: Get app routes
2 uri:
3 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes"
4 method: GET
5 validate_certs: no
6 headers:
7 apikey: "{{ kong_app_admin_apikey }}"
8 register: kong_app_service_routes_check
9
10- name: Setup route
11 uri:
12 url: "{{ kong_app_admin_url }}/services/{{ service.name }}/routes"
13 method: POST
14 body: "{{ route | to_json }}"
15 headers:
16 apikey: "{{ kong_app_admin_apikey }}"
17 Content-Type: application/json
18 status_code: 201
19 with_items: "{{ service.routes | default([]) }}"
20 loop_control:
21 loop_var: route
22
23- name: Delete old routes
24 uri:
25 url: "{{ kong_app_admin_url }}/routes/{{ item.id }}"
26 method: DELETE
27 headers:
28 apikey: "{{ kong_app_admin_apikey }}"
29 status_code: 204
30 with_items: "{{ kong_app_service_routes_check.json.data }}"
31 when: not kong_app_service_routes_check is skipped
diff --git a/tests/inventory b/tests/inventory
new file mode 100644
index 0000000..49d4fe2
--- /dev/null
+++ b/tests/inventory
@@ -0,0 +1,2 @@
1localhost ansible_connection=local
2
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..ed97d53
--- /dev/null
+++ b/vars/main.yml
@@ -0,0 +1 @@
---