-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws_mongo_test.yml
237 lines (225 loc) · 7.08 KB
/
aws_mongo_test.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
---
- name: Mongo test environment
hosts: localhost
vars:
MongoShardInstanceType: t2.micro
# MongoShardInstanceType: c3.2xlarge
MongoShardInstanceCount: 3
MongoConfigInstanceType: t2.micro
# MongoConfigInstanceType: c4.xlarge
MongoConfigInstanceCount: 3
PHPInstanceType: t2.micro
# PHPInstanceType: c4.xlarge
PHPInstanceCount: 1
gather_facts: False
tasks:
- name: Create Mongo VPC
ec2_vpc:
state: present
cidr_block: 10.0.0.0/16
region: us-west-2
resource_tags: {"t": "v"}
subnets:
- cidr: 10.0.0.0/16
az: us-west-2a
resource_tags: {"t": "v"}
internet_gateway: True
route_tables:
- subnets:
- 10.0.0.0/16
routes:
- dest: 0.0.0.0/0
gw: igw
wait: yes
register: ec2_vpc1
- name: Create security group
ec2_group:
description: SSH access
name: SSH_access
region: us-west-2
state: present
vpc_id: "{{ ec2_vpc1.vpc_id }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
register: ec2_group
- name: Create EC2 instances for MongoShards
ec2:
key_name: mongo
instance_type: "{{ MongoShardInstanceType }}"
image: ami-e7527ed7
region: us-west-2
wait: yes
group: ['SSH_access','default']
instance_tags:
MongoShard: True
exact_count: "{{ MongoShardInstanceCount }}"
count_tag: MongoShard
vpc_subnet_id: "{{ ec2_vpc1.subnets[0].id }}"
assign_public_ip: yes
# placement_group: mongo
volumes:
- device_name: /dev/xvdb
device_type: gp2
# iops: 1000
volume_size: 100
delete_on_termination: true
- device_name: /dev/xvdc
device_type: gp2
# iops: 1000
volume_size: 10
delete_on_termination: true
- device_name: /dev/xvdd
device_type: gp2
# iops: 1000
volume_size: 70
delete_on_termination: true
wait: yes
# ebs_optimized: yes
register: ec2_shards
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname=mongo_shards ansible_ssh_private_key_file=~/.ssh/mongo.pem.txt
with_items: ec2_shards.instances
- name: Wait for SSH to come up
wait_for: host={{ item.public_dns_name }} port=22 delay=5 timeout=320 state=started
with_items: ec2_shards.instances
- name: Get rid of SSH "Are you sure you want to continue connecting (yes/no)?" query
local_action: command sh -c 'ssh-keyscan -t ECDSA {{ item.public_ip }} >> $HOME/.ssh/known_hosts'
with_items: ec2_shards.instances
- name: Empty shardNodes
local_action: file path=/tmp/shardNodes state=absent
- name: Collect instances names
local_action: command sh -c 'echo sh.addShard\(\"{{ item.private_dns_name }}:27018\"\)\; >> /tmp/shardNodes'
with_items: ec2_shards.instances
- name: Create EC2 instances for MongoConfigs
ec2:
key_name: mongo
instance_type: "{{ MongoConfigInstanceType }}"
image: ami-e7527ed7
region: us-west-2
wait: yes
group: ['SSH_access','default']
instance_tags:
MongoConfig: True
exact_count: "{{ MongoConfigInstanceCount }}"
count_tag: MongoConfig
vpc_subnet_id: "{{ ec2_vpc1.subnets[0].id }}"
assign_public_ip: yes
# placement_group: mongo
volumes:
- device_name: /dev/xvdb
device_type: gp2
# iops: 1000
volume_size: 40
delete_on_termination: true
- device_name: /dev/xvdc
device_type: gp2
# iops: 1000
volume_size: 10
delete_on_termination: true
- device_name: /dev/xvdd
device_type: gp2
# iops: 1000
volume_size: 40
delete_on_termination: true
wait: yes
# ebs_optimized: yes
register: ec2_config
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname=mongo_configs ansible_ssh_private_key_file=~/.ssh/mongo.pem.txt
with_items: ec2_config.instances
- name: Wait for SSH to come up
wait_for: host={{ item.public_dns_name }} port=22 delay=5 timeout=320 state=started
with_items: ec2_config.instances
- name: Get rid of SSH "Are you sure you want to continue connecting (yes/no)?" query
local_action: command sh -c 'ssh-keyscan -t ECDSA {{ item.public_ip }} >> $HOME/.ssh/known_hosts'
with_items: ec2_config.instances
- name: Empty configNodes
local_action: file path=/tmp/configNodes state=absent
- name: Collect instances names
local_action: command sh -c 'echo {{ item.private_dns_name }}:27019, >> /tmp/configNodes'
with_items: ec2_config.instances
- name: Create EC2 instances for Mongos+PHP
ec2:
key_name: mongo
instance_type: "{{ PHPInstanceType }}"
image: ami-e7527ed7
region: us-west-2
wait: yes
group: ['SSH_access','default']
instance_tags:
PHP: True
exact_count: "{{ PHPInstanceCount }}"
count_tag: PHP
vpc_subnet_id: "{{ ec2_vpc1.subnets[0].id }}"
assign_public_ip: yes
# placement_group: mongo
volumes:
- device_name: /dev/xvdb
device_type: gp2
# iops: 1000
volume_size: 40
delete_on_termination: true
wait: yes
# ebs_optimized: yes
register: ec2_php
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname=php ansible_ssh_private_key_file=~/.ssh/mongo.pem.txt
with_items: ec2_php.instances
- name: Remember first mongos
add_host: hostname={{ ec2_php.instances[0].public_ip }} groupname=mongos_add_shards ansible_ssh_private_key_file=~/.ssh/mongo.pem.txt
- name: Wait for SSH to come up
wait_for: host={{ item.public_dns_name }} port=22 delay=5 timeout=320 state=started
with_items: ec2_php.instances
- name: Get rid of SSH "Are you sure you want to continue connecting (yes/no)?" query
local_action: command sh -c 'ssh-keyscan -t ECDSA {{ item.public_ip }} >> $HOME/.ssh/known_hosts'
with_items: ec2_php.instances
- name: Configure All instance(s)
hosts: mongo_shards:mongo_configs:php
sudo: True
user: ec2-user
gather_facts: True
roles:
- common
- mongo_common
- name: Configure Mongo instance(s)
hosts: mongo_shards:mongo_configs
sudo: True
user: ec2-user
gather_facts: True
roles:
- mongo_commonn_config_shard
- name: Configure MongoShards instance(s)
hosts: mongo_shards
sudo: True
user: ec2-user
gather_facts: True
roles:
- mongo_shard
- name: Configure MongoShards instance(s)
hosts: mongo_configs
sudo: True
user: ec2-user
gather_facts: True
roles:
- mongo_config
- name: Configure PHP instance(s)
hosts: php
sudo: True
user: ec2-user
gather_facts: True
roles:
- php
- mongos
- name: Add shards
hosts: mongos_add_shards
sudo: True
user: ec2-user
gather_facts: True
tasks:
- name: Copy list shards
copy: src=/tmp/shardNodes dest=/tmp/shardNodes
- name: Add shards
shell: mongo localhost /tmp/shardNodes