forked from edwardcallahan/conductr-ansible
-
Notifications
You must be signed in to change notification settings - Fork 11
/
build-cluster-ec2.yml
257 lines (224 loc) · 7.21 KB
/
build-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
---
#
# Build a cluster of nodes running core, agent and proxy, all w/public IPs
# Recommended for getting started, development and testing
#
- name: Provision and configure a ConductR cluster on AWS
hosts: localhost
connection: local
gather_facts: False
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: conductr/tasks/validate.yml
- name: Launch Seed Node
local_action:
module: ec2
image: "{{ NODE_IMAGE }}"
instance_type: "{{ NODE_INSTANCE_TYPE }}"
keypair: "{{ KEYPAIR }}"
region: "{{ EC2_REGION }}"
group_id: "{{ NODE_SG }}"
vpc_subnet_id: "{{ SN_1 }}"
assign_public_ip: yes
instance_tags:
Name: "{{ TAG_NAME }}"
Role: Seed Node
Version: "{{ CONDUCTR_VERSION}}"
count: 1
volumes:
- device_name: /dev/sda1
device_type: "{{ NODE_VOL_TYPE }}"
volume_size: "{{ NODE_VOL_SIZE }}"
delete_on_termination: true
wait: yes
register: ec2
- debug: msg="Seed node {{ ec2.instances[0].private_ip }} --- {{ ec2.instances[0].public_dns_name }}"
- name: Add seed to seeds_public
add_host:
groupname: "seeds_public"
hostname: "{{ ec2.instances[0].public_ip }}"
- name: Add seed to seeds_private
add_host:
groupname: "seeds_private"
hostname: "{{ ec2.instances[0].private_ip }}"
- name: Launch Nodes
local_action:
module: ec2
image: "{{ NODE_IMAGE }}"
instance_type: "{{ NODE_INSTANCE_TYPE }}"
keypair: "{{ KEYPAIR }}"
region: "{{ EC2_REGION }}"
group_id: "{{ NODE_SG }}"
vpc_subnet_id: "{{ item }}"
assign_public_ip: yes
instance_tags:
Name: "{{ TAG_NAME }}"
Role: Node
Version: "{{ CONDUCTR_VERSION}}"
count: 1
volumes:
- device_name: /dev/sda1
device_type: "{{ NODE_VOL_TYPE }}"
volume_size: "{{ NODE_VOL_SIZE }}"
delete_on_termination: true
wait: yes
register: ec2
with_items:
- "{{ SN_2 }}"
- "{{ SN_3 }}"
- name: Add public ip to nodes_public
add_host:
groupname: "nodes_public"
hostname: "{{ item.instances[0].public_ip }}"
with_items: "{{ ec2.results }}"
- name: Add private ip to nodes_private
add_host:
groupname: "nodes_private"
hostname: "{{ item.instances[0].private_ip }}"
with_items: "{{ ec2.results }}"
- name: Launch Template Nodes
local_action:
module: ec2
image: "{{ TEMPLATE_IMAGE }}"
instance_type: "{{ TEMPLATE_INSTANCE_TYPE }}"
keypair: "{{ KEYPAIR }}"
region: "{{ EC2_REGION }}"
group_id: "{{ NODE_SG }}"
vpc_subnet_id: "{{ item }}"
assign_public_ip: yes
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_1 }}"
- name: Save template node ip
add_host:
groupname: "template_nodes"
hostname: "{{ item.instances[0].public_ip }}"
with_items: "{{ ec2.results }}"
- name: Wait for SSH to come up
wait_for:
host: "{{ item.instances[0].public_dns_name }}"
port: 22
delay: 60
timeout: 320
state: started
with_items: "{{ ec2.results }}"
- name: Setup ConductR Seed
hosts: seeds_public
user: "{{ REMOTE_USER }}"
gather_facts: False
sudo: True
vars:
# These are the default ConductR roles - these roles may be overridden within the VARS_FILE
CONDUCTR_AGENT_ROLES:
- web
- haproxy
- elasticsearch
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: python/tasks/main.yml
- include: java/tasks/openjdk.yml
- include: docker/tasks/main.yml
when: "{{ INSTALL_DOCKER }} == true"
- include: ntp/tasks/main.yml
- include: haproxy/tasks/main.yml
- include: conductr/tasks/install-core-seed.yml
- include: conductr/tasks/install-agent.yml
vars:
CORE_OBSERVER_PRIVATE_IP: "{{ groups.seeds_private[0] }}"
- include: bundle/tasks/config-elasticsearch.yml
- include: bundle/tasks/config-haproxy.yml
- name: Setup ConductR Nodes (non-seed)
hosts: nodes_public
user: "{{ REMOTE_USER }}"
gather_facts: False
sudo: True
vars:
# These are the default ConductR roles - these roles may be overridden within the VARS_FILE
CONDUCTR_AGENT_ROLES:
- web
- haproxy
- elasticsearch
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: python/tasks/main.yml
- include: java/tasks/openjdk.yml
- include: docker/tasks/main.yml
when: "{{ INSTALL_DOCKER }} == true"
- include: ntp/tasks/main.yml
- include: haproxy/tasks/main.yml
- include: conductr/tasks/install-core.yml
VARS:
CORE_SEED_PRIVATE_IP: "{{ groups.seeds_private[0] }}"
- include: conductr/tasks/install-agent.yml
vars:
CORE_OBSERVER_PRIVATE_IP: "{{ groups.seeds_private[0] }}"
- include: bundle/tasks/config-elasticsearch.yml
- include: bundle/tasks/config-haproxy.yml
- name: Install ConductR HAProxy from the seed node
hosts: seeds_public
user: "{{ REMOTE_USER }}"
gather_facts: 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"
- pause:
prompt: "Allowing instances to become healthy. Abort to not launch template instance, requiring manual registration w/ELB"
seconds: 90
- name: Setup Template Node
hosts: template_nodes
user: "{{ REMOTE_USER }}"
gather_facts: False
sudo: True
vars:
# These are the default ConductR roles - these roles may be overridden within the VARS_FILE
CONDUCTR_AGENT_ROLES:
- web
- haproxy
- elasticsearch
vars_files:
- "{{ VARS_FILE }}"
tasks:
- include: python/tasks/main.yml
- include: java/tasks/openjdk.yml
- include: docker/tasks/main.yml
when: "{{ INSTALL_DOCKER }} == true"
- include: ntp/tasks/main.yml
- include: haproxy/tasks/main.yml
- include: conductr/tasks/install-core-seed.yml
- include: conductr/tasks/install-agent.yml
vars:
CORE_OBSERVER_PRIVATE_IP: "127.0.0.1"
- include: bundle/tasks/config-elasticsearch.yml
- include: bundle/tasks/config-haproxy.yml
- name: Register ConductR with ELB
hosts: nodes_public
user: "{{ REMOTE_USER }}"
gather_facts: False
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