-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.yml
278 lines (278 loc) · 11.6 KB
/
demo.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
---
- name: Deploy Dimension Data infrastructure
hosts: localhost
vars:
root_password: P$$ssWwrrdGoDd!
vars_files:
- /root/caas_credentials.yml
tasks:
- name: Check credentials (optionnal Step)
caas_credentials:
username: "{{caas_credentials.username}}"
password: "{{caas_credentials.password}}"
apiurl: "{{caas_credentials.apiurl}}"
datacenter: "{{caas_credentials.datacenter}}"
# register: caas_credentials
# - name: print debug
# debug: var=caas_credentials
- name: Deploy my Nework Domain
caas_networkdomain:
caas_credentials: "{{ caas_credentials }}"
name: ansible.CaaS_Sandbox
type: ADVANCED
register: caas_networkdomain
# - name: print debug
# debug: var=caas_networkdomain
- name: Deploy WebServers DMZ
caas_vlan:
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
name: "{{caas_networkdomain.networkdomains.networkDomain[0].name}}_vlan_webservers"
privateIpv4BaseAddress: "192.168.30.0"
register: caas_vlan_webservers
- name: print debug
debug: var=caas_vlan_webservers
# - name: Deploy WebServers DMZ
# caas_server:
# caas_credentials: "{{ caas_credentials }}"
# name: "MyWebServer"
# imageName: CentOS 7 64-bit 2 CPU
# administratorPassword: "{{ root_password }}"
# networkInfo:
# networkDomainName: ansible.Caas_SandBox
# primaryNic:
# privateIpv4: 192.168.30.42
# register: caas_mywebserver
# - name: print debug
# debug: var=caas_mywebserver
- name: Deploy WebServers
caas_server:
caas_credentials: "{{ caas_credentials }}"
wait: False
name: "WebServer"
#state: "absent"
#action: shutdownServer
count: 2
#description: ansible.CaaS This a test, feel free to delete
#imageId: bfe177f0-23ec-4886-a046-c516f354fd53
imageName: CentOS 7 64-bit 2 CPU
administratorPassword: "{{ root_password }}"
#cpu:
#count: 16
#coresPerSocket: 1
#speed: STANDARD
networkInfo:
#networkDomainId: fd340f41-7f93-4dda-a7f2-e46cc6302613
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
primaryNic:
#vlanId: 0cd34569-e3b4-46ca-9c86-3e8c2b08d732
vlanName: "{{caas_vlan_webservers.vlans.vlan[0].name}}"
#privateIpv4: 172.24.42.42
register: caas_webservers
- name: print debug
debug: var=caas_webservers
- name: Deploy AppServers DMZ
caas_vlan:
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
name: "{{caas_networkdomain.networkdomains.networkDomain[0].name}}_vlan_appservers"
privateIpv4BaseAddress: "192.168.40.0"
register: caas_vlan_appservers
- name: Deploy AppServers
caas_server:
caas_credentials: "{{ caas_credentials }}"
name: "AppServer"
wait: False
imageName: CentOS 7 64-bit 2 CPU
administratorPassword: "{{ root_password }}"
networkInfo:
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
primaryNic:
vlanName: "{{caas_vlan_appservers.vlans.vlan[0].name}}"
register: caas_appservers
# - name: Deploy DBServers DMZ
# caas_vlan:
# caas_credentials: "{{ caas_credentials }}"
# networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
# name: "{{caas_networkdomain.networkdomains.networkDomain[0].name}}_vlan_dbservers"
# privateIpv4BaseAddress: "192.168.50.0"
# register: caas_vlan_dbservers
# - name: Deploy DBServers
# caas_server:
# caas_credentials: "{{ caas_credentials }}"
# name: "DBServer"
# wait: True
# imageName: CentOS 7 64-bit 2 CPU
# administratorPassword: "{{ root_password }}"
# networkInfo:
# networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
# primaryNic:
# vlanName: "{{caas_vlan_dbservers.vlans.vlan[0].name}}"
# register: caas_dbserver
- name: Disable Default Rule that Drop Any external IPv6 connection
caas_firewallrule:
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
name: "CCDEFAULT.DenyExternalInboundIPv6"
enabled: False
- name: Add FireWall Rule to allow IPv6 SSH for Ansible
caas_firewallrule:
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
name: "ssh_for_ansible_to_vlan_webservers"
action: "ACCEPT_DECISIVELY"
ipVersion: "IPV6"
protocol: "TCP"
source:
ip:
address: "{{ ansible_all_ipv6_addresses[0] }}"
destination:
ip:
address: "{{ caas_vlan_webservers.vlans.vlan[0].ipv6Range.address }}"
prefixSize: "{{ caas_vlan_webservers.vlans.vlan[0].ipv6Range.prefixSize }}"
port:
begin: 22
placement:
position: "LAST"
- name: Add FireWall Rule to allow IPv6 SSH for Ansible
caas_firewallrule:
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
name: "ssh_for_ansible_to_vlan_appservers"
action: "ACCEPT_DECISIVELY"
ipVersion: "IPV6"
protocol: "TCP"
source:
ip:
address: "{{ ansible_all_ipv6_addresses[0] }}"
destination:
ip:
address: "{{ caas_vlan_appservers.vlans.vlan[0].ipv6Range.address }}"
prefixSize: "{{ caas_vlan_appservers.vlans.vlan[0].ipv6Range.prefixSize }}"
port:
begin: 22
placement:
position: "LAST"
- name: Add FireWall Rule to allow Web 2 App
caas_firewallrule:
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
name: "Web2App"
source:
ip:
address: "{{ caas_vlan_webservers.vlans.vlan[0].privateIpv4Range.address }}"
prefixSize: "{{ caas_vlan_webservers.vlans.vlan[0].privateIpv4Range.prefixSize }}"
destination:
ip:
address: "{{ caas_vlan_appservers.vlans.vlan[0].privateIpv4Range.address }}"
prefixSize: "{{ caas_vlan_appservers.vlans.vlan[0].privateIpv4Range.prefixSize }}"
port:
begin: 3000
placement:
position: "FIRST"
register: caas_firewallrule
- name: print debug
debug: var=caas_firewallrule
- name: Wait for WebServers end of deployment
caas_server:
caas_credentials: "{{ caas_credentials }}"
name: "WebServer"
count: 2
imageName: CentOS 7 64-bit 2 CPU
administratorPassword: "{{ root_password }}"
networkInfo:
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
primaryNic:
vlanName: "{{caas_vlan_webservers.vlans.vlan[0].name}}"
register: caas_webservers
#- name: Wait for SSH to come up
# wait_for: host="{{ item.networkInfo.primaryNic.ipv6 }}" port=22 timeout=9000 state=started
#when: item.started
# with_items: caas_webservers.servers.server
#- pause: seconds=30
- name: Get Public IPv4
caas_publicip:
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
#minFreePublicIpv4Address: 1
register: caas_publicp
- name: print debug
debug: var=caas_publicp
- name: Setting Load Balancing for WebServers
caas_loadbalancer:
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
name: "WebServers.Load.Balancer"
# type: STANDARD
# protocol: TCP
# port: 80
# connectionLimit: 25000
# connectionRateLimit: 2000
# sourcePortPreservation: PRESERVE
# optimizationProfile: TCP
pool:
# name: webservers.pool
# loadBalanceMethod: ROUND_ROBIN
# serviceDownAction: "RESELECT"
# slowRampTime: 10
node:
- name: "webservers.node_{{item.name}}_{{item.networkInfo.primaryNic.privateIpv4}}"
description: "WebServer"
ipv4Address: "{{item.networkInfo.primaryNic.privateIpv4}}"
status: ENABLED
port: 80
connectionLimit: 20000
connectionRateLimit: 2000
#when: item.started
register: caas_loadbalancer
with_items: "{{caas_webservers.servers.server}}"
- name: Deploy a public NAT
caas_nat:
#state: absent
caas_credentials: "{{ caas_credentials }}"
networkDomainName: "{{ caas_networkdomain.networkdomains.networkDomain[0].name }}"
internalIp: "{{caas_appservers.servers.server[0].networkInfo.primaryNic.privateIpv4}}"
#externalIp: 192.168.110.1
register: caas_nat
- name: Add new instances to group WebServers
add_host: name="{{ item.id }}" ansible_ssh_host="{{ item.networkInfo.primaryNic.ipv6 }}" ansible_ssh_pass="{{ root_password }}" groupname=WebServers
#when: item.started
with_items: "{{caas_webservers.servers.server}}"
- name: Add new instances to group AppServers
add_host: name="{{ item.id }}" ansible_ssh_host="{{ item.networkInfo.primaryNic.ipv6 }}" ansible_ssh_pass="{{ root_password }}" groupname=AppServers
#when: item.started
with_items: "{{caas_appservers.servers.server}}"
- name: Wait for SSH to come up
wait_for: host="{{ item.networkInfo.primaryNic.ipv6 }}" port=22 timeout=600 state=started
#when: item.started
with_items: "{{caas_appservers.servers.server}}"
# - name: Configure Web Servers
# hosts: WebServers
# vars:
# apache_listen_port: 80
# apache_vhosts:
# - {servername: "example.com", documentroot: "/var/www/vhosts/example_com"}
# php_packages: ["php","php-cli","php-devel","php-pdo"]
# roles:
# - { role: geerlingguy.apache }
# - { role: geerlingguy.php }
# - name: Deploy Web Site
# hosts: WebServers
# tasks:
# - yum: name=git
# - git: repo=https://github.com/job-so/ansible.CaaS.demo.webserver.git dest=/var/www/vhosts/example_com
# - name: Configure App Servers
# hosts: AppServers
# vars:
# nodejs_forever: true
# nodejs_npm_global_packages:
# - name: express
# - name: mongodb
# roles:
# - { role: geerlingguy.nodejs }
# - name: Deploy and run Application
# hosts: AppServers
# tasks:
# - yum: name=git
# - git: repo=https://github.com/job-so/ansible.CaaS.demo.appserver.git dest=/root/app
# - command: forever start /root/app/app.js