forked from toast38coza/ansible-kong-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_and_routes_playbook.yml
171 lines (141 loc) · 4.26 KB
/
service_and_routes_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
##########################################################
# To use this playbook it is necessary to install: #
# - Python #
# - Python "requests" module (sudo pip install requests) #
##########################################################
- hosts: localhost
vars:
- kong_admin_base_url: "http://172.20.0.103:81"
- kong_base_url: "http://172.20.0.103:80"
- service_name: "myservice"
tasks:
- name: List existing services
kong_service:
kong_admin_uri: "{{kong_admin_base_url}}"
state: list
register: result
- set_fact:
existing_services: "{{result.meta.data}}"
- name: Prompt
pause:
prompt: "WARNING: There are services already configured which WILL BE DELETED if you proceed, do you wish to continue (y/n) ?"
register: result
when: existing_services | length > 0
- debug:
var: result.user_input
when: existing_services | length > 0
- name:
meta: end_play
when: (existing_services | length > 0) and not (result.user_input == "y" or result.user_input == "Y")
- name: List routes by service
kong_routes:
kong_admin_uri: "{{kong_admin_base_url}}"
serviceid: "{{item.id}}"
state: list
register: result
with_items:
- "{{existing_services}}"
- name: Delete routes by service
kong_routes:
kong_admin_uri: "{{kong_admin_base_url}}"
serviceid: "{{item.id}}"
state: absent
with_items:
- "{{existing_services}}"
- name: Delete existing services
kong_service:
kong_admin_uri: "{{kong_admin_base_url}}"
serviceid: "{{item.id}}"
state: absent
with_items:
- "{{existing_services}}"
- debug:
var: result.meta
- name: List services (before)
kong_service:
kong_admin_uri: "{{kong_admin_base_url}}"
state: list
register: result
- debug:
var: result.meta
- name: Register service
kong_service:
kong_admin_uri: "{{kong_admin_base_url}}"
name: "{{service_name}}"
state: present
url: "http://172.23.0.21/myservice"
retries: 5
connect_timeout: 60000
write_timeout: 60000
read_timeout: 60000
register: result
- set_fact:
serviceid: "{{result.meta.id}}"
- name: List services (middle)
kong_service:
kong_admin_uri: "{{kong_admin_base_url}}"
state: list
register: result
- debug:
var: result.meta
- name: List routes (before)
kong_routes:
kong_admin_uri: "{{kong_admin_base_url}}"
state: list
register: result
- debug:
var: result.meta
- name: Add route
kong_routes:
kong_admin_uri: "{{kong_admin_base_url}}"
serviceid: "{{serviceid}}"
state: present
protocols: ["https"]
methods: ["GET"]
hosts: ["example.com"]
paths: ['/my-path']
register: result
- set_fact:
routeid: "{{result.meta.id}}"
- name: Update route
kong_routes:
kong_admin_uri: "{{kong_admin_base_url}}"
serviceid: "{{serviceid}}"
routeid: "{{routeid}}"
state: present
protocols: ["https"]
methods: ["GET","POST"]
hosts: ["example.com"]
paths: ['/my-path']
register: result
- name: List routes (middle)
kong_routes:
kong_admin_uri: "{{kong_admin_base_url}}"
state: list
register: result
- debug:
var: result.meta
- name: Delete route
kong_routes:
kong_admin_uri: "{{kong_admin_base_url}}"
routeid: "{{routeid}}"
state: absent
- name: List routes (after)
kong_routes:
kong_admin_uri: "{{kong_admin_base_url}}"
state: list
register: result
- debug:
var: result.meta
- name: Delete service
kong_service:
kong_admin_uri: "{{kong_admin_base_url}}"
name: "{{service_name}}"
state: absent
- name: List services (after)
kong_service:
kong_admin_uri: "{{kong_admin_base_url}}"
state: list
register: result
- debug:
var: result.meta