forked from edwardcallahan/conductr-ansible
-
Notifications
You must be signed in to change notification settings - Fork 11
/
build-private-agent-cluster-ec2.yml
336 lines (294 loc) · 9.55 KB
/
build-private-agent-cluster-ec2.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#
# Builds a cluster of nodes in a configuraion more typical of production workloads.
# Core and agent nodes are not given public IPs and public agent nodes are used for proxying.
# Recommended for advanced users
#
# This playbook requires SSH access to instances private interfaces
# Run from the bastion host of create playbook or another node with access to the private network
#
---
- name: Provision and configure a ConductR cluster w/ Private Agents on AWS EC2
hosts: localhost
connection: local
gather_facts: False
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: conductr/tasks/validate.yml
- name: Launch Core Seed
local_action:
module: ec2
image: "{{ CORE_IMAGE }}"
instance_type: "{{ CORE_INSTANCE_TYPE }}"
keypair: "{{ KEYPAIR }}"
region: "{{ EC2_REGION }}"
group_id: "{{ CORE_SG }}"
vpc_subnet_id: "{{ SN_PRIVATE_1 }}"
assign_public_ip: no
instance_tags:
Name: "{{ TAG_NAME }} Core"
Role: Core
Seed: True
Version: "{{ CONDUCTR_VERSION }}"
count: 1
volumes:
- device_name: /dev/sda1
device_type: "{{ CORE_VOL_TYPE }}"
volume_size: "{{ CORE_VOL_SIZE }}"
delete_on_termination: true
wait: yes
register: ec2
- debug: msg="Seed node {{ ec2.instances[0].private_ip }}"
- name: Add seed to seeds_nodes
add_host:
groupname: "seeds_private"
hostname: "{{ ec2.instances[0].private_ip }}"
- name: Launch Core Nodes
local_action:
module: ec2
image: "{{ CORE_IMAGE }}"
instance_type: "{{ CORE_INSTANCE_TYPE }}"
keypair: "{{ KEYPAIR }}"
region: "{{ EC2_REGION }}"
group_id: "{{ CORE_SG }}"
vpc_subnet_id: "{{ item }}"
assign_public_ip: no
instance_tags:
Name: "{{ TAG_NAME }} Core"
Role: Core
Version: "{{ CONDUCTR_VERSION}}"
count: 1
volumes:
- device_name: /dev/sda1
device_type: "{{ CORE_VOL_TYPE }}"
volume_size: "{{ CORE_VOL_SIZE }}"
delete_on_termination: true
wait: yes
register: ec2
with_items:
- "{{ SN_PRIVATE_2 }}"
- "{{ SN_PRIVATE_3 }}"
- name: Add private ip to core_nodes
add_host:
groupname: "core_nodes"
hostname: "{{ item.instances[0].private_ip }}"
with_items: "{{ ec2.results }}"
- name: Launch Private Agent Nodes
local_action:
module: ec2
image: "{{ PRIVATE_AGENT_IMAGE }}"
instance_type: "{{ PRIVATE_AGENT_INSTANCE_TYPE }}"
keypair: "{{ KEYPAIR }}"
region: "{{ EC2_REGION }}"
group_id: "{{ PRIVATE_AGENT_SG }}"
vpc_subnet_id: "{{ item }}"
assign_public_ip: no
instance_tags:
Name: "{{ TAG_NAME }} Private Agent"
Role: Private Agent
Version: "{{ CONDUCTR_VERSION}}"
volumes:
- device_name: /dev/sda1
device_type: "{{ PRIVATE_AGENT_VOL_TYPE }}"
volume_size: "{{ PRIVATE_AGENT_VOL_SIZE }}"
delete_on_termination: true
wait: yes
register: ec2
with_items:
- "{{ SN_PRIVATE_1 }}"
- "{{ SN_PRIVATE_2 }}"
- "{{ SN_PRIVATE_3 }}"
- name: Add ip to private_agents
add_host:
groupname: "private_agents"
hostname: "{{ item.instances[0].private_ip }}"
with_items: "{{ ec2.results }}"
- name: Launch Public Proxy Nodes
local_action:
module: ec2
image: "{{ PUBLIC_AGENT_IMAGE }}"
instance_type: "{{ PUBLIC_AGENT_INSTANCE_TYPE }}"
keypair: "{{ KEYPAIR }}"
region: "{{ EC2_REGION }}"
group_id: "{{ PUBLIC_AGENT_SG }}"
vpc_subnet_id: "{{ item }}"
assign_public_ip: yes
instance_tags:
Name: "{{ TAG_NAME }} Public Agent"
Role: Public Agent
Version: "{{ CONDUCTR_VERSION}}"
count: 1
volumes:
- device_name: /dev/sda1
device_type: "{{ PUBLIC_AGENT_VOL_TYPE }}"
volume_size: "{{ PUBLIC_AGENT_VOL_SIZE }}"
delete_on_termination: true
wait: yes
register: ec2
with_items:
- "{{ SN_PUBLIC_1 }}"
- "{{ SN_PUBLIC_2 }}"
- name: Add public node private ips to public_agents
add_host:
groupname: "public_agents"
hostname: "{{ item.instances[0].private_ip }}"
with_items: "{{ ec2.results }}"
- name: Add public node public ips to public_agents_public
add_host:
groupname: "public_agents_public"
hostname: "{{ item.instances[0].public_ip }}"
with_items: "{{ ec2.results }}"
- name: Launch Template Node for imaging
local_action:
module: ec2
image: "{{ TEMPLATE_IMAGE }}"
instance_type: "{{ TEMPLATE_INSTANCE_TYPE }}"
keypair: "{{ KEYPAIR }}"
region: "{{ EC2_REGION }}"
group_id: "{{ PRIVATE_AGENT_SG }}"
vpc_subnet_id: "{{ item }}"
assign_public_ip: no
instance_tags:
Name: "{{ TAG_NAME }} Template"
Role: Template
Version: "{{ CONDUCTR_VERSION}}"
count: 1
volumes:
- device_name: /dev/sda1
device_type: "{{ TEMPLATE_VOL_TYPE }}"
volume_size: "{{ TEMPLATE_VOL_SIZE }}"
delete_on_termination: true
wait: yes
register: ec2
with_items:
- "{{ SN_PRIVATE_1 }}"
- name: Save template node ip
add_host:
groupname: "template_nodes"
hostname: "{{ item.instances[0].private_ip }}"
with_items: "{{ ec2.results }}"
- name: Wait for SSH to come up
wait_for:
host: "{{ item.instances[0].private_ip }}"
port: 22
delay: 60
timeout: 320
state: started
with_items: "{{ ec2.results }}"
- name: Setup Seed Node
hosts: seeds_private
user: "{{ REMOTE_USER }}"
gather_facts: False
sudo: True
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: python/tasks/main.yml
- include: java/tasks/openjdk.yml
- include: ntp/tasks/main.yml
- include: conductr/tasks/install-core-seed.yml
- name: Setup Core Nodes
hosts: core_nodes
user: "{{ REMOTE_USER }}"
gather_facts: False
sudo: True
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: python/tasks/main.yml
- include: java/tasks/openjdk.yml
- include: ntp/tasks/main.yml
- include: conductr/tasks/install-core.yml
- name: Setup Private Nodes
hosts: private_agents
user: "{{ REMOTE_USER }}"
gather_facts: False
sudo: True
vars:
# These are the default ConductR Private Agent roles - these roles may be overridden within the VARS_FILE
CONDUCTR_PRIVATE_AGENT_ROLES:
- web
- elasticsearch
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: python/tasks/main.yml
- include: java/tasks/openjdk.yml
- include: ntp/tasks/main.yml
- include: docker/tasks/main.yml
when: "{{ INSTALL_DOCKER }} == true"
- include: conductr/tasks/install-agent.yml
vars:
CORE_OBSERVER_PRIVATE_IP: "{{ groups.seeds_private[0] }}"
CONDUCTR_AGENT_ROLES: "{{ CONDUCTR_PRIVATE_AGENT_ROLES }}"
- include: bundle/tasks/config-elasticsearch.yml
- name: Setup Public Agent Nodes
hosts: public_agents
user: "{{ REMOTE_USER }}"
gather_facts: False
sudo: True
vars:
# These are the default ConductR Public Agent roles - these roles may be overridden within the VARS_FILE
CONDUCTR_PUBLIC_AGENT_ROLES:
- haproxy
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: python/tasks/main.yml
- include: java/tasks/openjdk.yml
- include: ntp/tasks/main.yml
- include: docker/tasks/main.yml
when: "{{ INSTALL_DOCKER }} == true"
- include: haproxy/tasks/main.yml
- include: conductr/tasks/install-agent.yml
vars:
CORE_OBSERVER_PRIVATE_IP: "{{ groups.seeds_private[0] }}"
CONDUCTR_AGENT_ROLES: "{{ CONDUCTR_PUBLIC_AGENT_ROLES }}"
- include: bundle/tasks/config-haproxy.yml
- name: Setup Template Node
hosts: template_nodes
user: "{{ REMOTE_USER }}"
gather_facts: False
sudo: True
vars:
# These are the default ConductR Public Agent roles - these roles may be overridden within the VARS_FILE
CONDUCTR_TEMPLATE_AGENT_ROLES:
- web
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: python/tasks/main.yml
- include: java/tasks/openjdk.yml
- include: ntp/tasks/main.yml
- include: docker/tasks/main.yml
when: "{{ INSTALL_DOCKER }} == true"
- include: conductr/tasks/install-agent.yml
vars:
CORE_OBSERVER_PRIVATE_IP: "127.0.0.1"
CONDUCTR_AGENT_ROLES: "{{ CONDUCTR_TEMPLATE_AGENT_ROLES }}"
- name: Install Bundles from the seed node
hosts: seeds_private
user: "{{ REMOTE_USER }}"
gather_facts: True
sudo: True
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: "conductr/tasks/install-access-token.yml"
- include: "bundle/tasks/install-elasticsearch.yml"
- include: "bundle/tasks/install-conductr-haproxy.yml"
- include: "bundle/tasks/install-kibana.yml"
- include: "bundle/tasks/install-visualizer.yml"
- name: Register Public Agent Nodes with ELB
hosts: public_agents
user: "{{ REMOTE_USER }}"
gather_facts: True
sudo: True
vars:
# Get these from env to workaround https://github.com/ansible/ansible/issues/10638
aws_access_key: "{{ lookup('env','AWS_ACCESS_KEY_ID') }}"
aws_secret_key: "{{ lookup('env','AWS_SECRET_ACCESS_KEY') }}"
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: conductr/tasks/register-elb.yml