--- /dev/null
+[defaults]
+roles_path=../
--- /dev/null
+---
+kong_app_admin_apikey: ""
+kong_app_plugins: []
+kong_app_routes: []
--- /dev/null
+---
+# handlers file for ansible-kong-app
\ No newline at end of file
--- /dev/null
+galaxy_info:
+ author: FretLink team
+ description: Love and trucks
+ company: FretLink
+
+ # If the issue tracker for your role is not on github, uncomment the
+ # next line and provide a value
+ # issue_tracker_url: http://example.com/issue/tracker
+
+ # Some suggested licenses:
+ # - BSD (default)
+ # - MIT
+ # - GPLv2
+ # - GPLv3
+ # - Apache
+ # - CC-BY
+ license: TBD
+
+ min_ansible_version: 2.4
+
+ # If this a Container Enabled role, provide the minimum Ansible Container version.
+ # min_ansible_container_version:
+
+ # Optionally specify the branch Galaxy will use when accessing the GitHub
+ # repo for this role. During role install, if no tags are available,
+ # Galaxy will use this branch. During import Galaxy will access files on
+ # this branch. If Travis integration is configured, only notifications for this
+ # branch will be accepted. Otherwise, in all cases, the repo's default branch
+ # (usually master) will be used.
+ #github_branch:
+
+ #
+ # platforms is a list of platforms, and each platform has a name and a list of versions.
+ #
+ # platforms:
+ # - name: Fedora
+ # versions:
+ # - all
+ # - 25
+ # - name: SomePlatform
+ # versions:
+ # - all
+ # - 1.0
+ # - 7
+ # - 99.99
+
+ galaxy_tags: []
+ # List tags for your role here, one per line. A tag is a keyword that describes
+ # and categorizes the role. Users find roles by searching for tags. Be sure to
+ # remove the '[]' above, if you add tags to this list.
+ #
+ # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
+ # Maximum 20 tags per role.
+
+dependencies: []
+ # List your role dependencies here, one per line. Be sure to remove the '[]' above,
+ # if you add dependencies to this list.
--- /dev/null
+- name: Check if service exists
+ uri:
+ url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}"
+ method: GET
+ headers:
+ apikey: "{{ 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/{{ kong_app_service_name }}"
+# method: "{{ (kong_app_check_service.status_code == 404) | ternary ('POST', 'PATCH') }}"
+# body: "{{ kong_app_service_body | to_json }}"
+# headers:
+# apikey: "{{ kong_app_admin_apikey }}"
+# Content-Type: application/json
+# status_code: 200,201
+
+- name: Setup plugins
+ import_tasks: plugins.yml
+
+- name: Setup routes
+ import_tasks: routes.yml
--- /dev/null
+---
+- name: Include kong-app tasks
+ import_tasks: kong-app.yml
+ tags:
+ - kong-app
--- /dev/null
+- name: Get plugins
+ uri:
+ url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins"
+ method: GET
+ validate_certs: no
+ register: kong_app_service_plugins_check
+
+- name: Set plugins facts
+ set_fact:
+ kong_app_current_plugins: "{{ kong_app_service_plugins_check.json | default('{}') | from_json }}"
+
+- name: Setup plugin {{ plugin.name }}
+ uri:
+ url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/plugins"
+ method: "{{ (current_config == {}) | 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 }}"
+ loop_control:
+ loop_var: plugin
+ vars:
+ current_config: "{{ kong_app_current_plugins.data | selectattr('name', plugin.name) | first |default({}) }}"
+ current_id_hash:
+ id: "{{ current_config.id | default('')}}"
+ current_body: "{{ (current_id_hash.id == '') | ternary({}, current_id_hash) }}"
--- /dev/null
+- name: Get app routes
+ uri:
+ url: "{{ kong_app_admin_url }}/services/{{ kong_app_service_name }}/routes"
+ method: GET
+ validate_certs: no
+ register: kong_app_service_routes_check
+
+- name: Set routes facts
+ set_fact:
+ kong_app_current_routes: "{{ kong_app_service_routes_check.json |default('{\"data\": []}') | from_json }}"
+
+- name: Setup route
+ uri:
+ url: "{{ kong_app_admin_url }}/services/{{ kong_app_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 }}"
+ loop_control:
+ loop_var: route
+
+- name: Delete old routes
+ uri:
+ url: "{{ kong_app_admin_url }}/services/routes/{{ item.id }}"
+ method: DELETE
+ headers:
+ apikey: "{{ kong_app_admin_apikey }}"
+ status_code: 204
+ with_items: "{{ kong_app_current_routes.data }}"
--- /dev/null
+localhost
+
--- /dev/null
+---
+- hosts: localhost
+ remote_user: root
+ roles:
+ - role: ansible-kong-app
+ kong_app_admin_url: http://127.0.0.1:8000
+ kong_app_service_name: toto
+ kong_app_service_url: http://example.com
--- /dev/null
+---
+kong_app_service_body:
+ name: "{{ kong_app_service_name }}"
+ url: "{{ kong_app_service_url }}"