Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Last active February 24, 2017 15:39
Show Gist options
  • Save toast38coza/12c8c3f60ca626c56f96 to your computer and use it in GitHub Desktop.
Save toast38coza/12c8c3f60ca626c56f96 to your computer and use it in GitHub Desktop.
- 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