Last active
February 24, 2017 15:39
-
-
Save toast38coza/12c8c3f60ca626c56f96 to your computer and use it in GitHub Desktop.
Playbook for [Kong tutorial](http://blog.toast38coza.me/kong-up-and-running-part-2-defining-our-api-gateway-with-ansible/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - hosts: localhost | |
| vars: | |
| - kong_admin_base_url: "http://api.example.com:8001" | |
| - kong_base_url: "http://api.example.com:8000" | |
| - kong_consumers: | |
| - username: Jason | |
| key: 123 | |
| tasks: | |
| - name: Register APIs | |
| kong_api: | |
| kong_admin_uri: "{{kong_admin_base_url}}" | |
| name: "mockbin" | |
| upstream_url: "http://mockbin.com" | |
| request_host: "mockbin.com" | |
| request_path: "/mockbin" | |
| strip_request_path: yes | |
| state: present | |
| - name: Verify API was added | |
| uri: | |
| url: "{{kong_admin_base_url}}/apis/mockbin" | |
| status_code: 200 | |
| - name: Add key authentication | |
| kong_plugin: | |
| kong_admin_uri: "{{kong_admin_base_url}}" | |
| api_name: "mockbin" | |
| plugin_name: "key-auth" | |
| state: present | |
| - name: Verify key auth was added | |
| uri: | |
| url: "{{kong_base_url}}/mockbin" | |
| status_code: 401 | |
| - name: Add a consumer | |
| kong_consumer: | |
| kong_admin_uri: "{{kong_admin_base_url}}" | |
| username: "{{item.username}}" | |
| state: present | |
| with_items: "{{kong_consumers}}" | |
| - name: Configure consumer | |
| kong_consumer: | |
| kong_admin_uri: "{{kong_admin_base_url}}" | |
| username: "{{item.username}}" | |
| api_name: key-auth | |
| data: | |
| key: "{{item.key}}" | |
| state: configure | |
| with_items: "{{kong_consumers}}" | |
| - name: Verify consumers can access API | |
| uri: | |
| url: "{{kong_base_url}}/mockbin" | |
| HEADER_apikey: "{{item.key}}" | |
| status_code: 200 | |
| with_items: "{{kong_consumers}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment