forked from toast38coza/ansible-kong-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
59 lines (52 loc) · 1.59 KB
/
playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
- hosts: localhost
vars:
- kong_admin_base_url: "http://192.168.99.100:8001"
- kong_base_url: "http://192.168.99.100: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}}"