-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_instances.yml
155 lines (134 loc) · 3.96 KB
/
create_instances.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
---
# use environment variables to set AWS EC2 creds
- hosts: "{{ target|default('localhost') }}"
tasks:
- name: "{{ key_name }} ec2 key in us-west-1"
ec2_key:
region: us-west-1
name: "{{ key_name }}"
key_material: "{{ item }}"
with_file: ~/.ssh/ec2_mongo.pem.pub
- name: "{{ key_name }} ec2 key in us-west-2"
ec2_key:
region: us-west-2
name: "{{ key_name }}"
key_material: "{{ item }}"
with_file: ~/.ssh/ec2_mongo.pem.pub
- name: "add {{ secgroup }} security group"
ec2_group:
name: "{{ secgroup }}"
description: "{{ secgroup }} security group in {{ item.key }}"
vpc_id: "{{ item.value.vpc }}"
region: "{{ item.key }}"
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 27017
to_port: 27017
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 27018
to_port: 27018
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 27019
to_port: 27019
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 28017
to_port: 28017
cidr_ip: 0.0.0.0/0
with_dict: "{{ regions }}"
- name: "launch {{ cluster_size }} instances"
ec2:
key_name: "{{ key_name }}"
region: "{{ item.key }}"
vpc_subnet_id: "{{ item.value.vpc_subnet }}"
instance_type: "{{ instance_type }}"
image: "{{ item.value.ami }}"
wait: yes
group: "{{ secgroup }}"
count: "{{ cluster_size }}"
assign_public_ip: yes
with_dict: "{{ regions }}"
- name: gather facts from us-west-1
ec2_remote_facts:
region: us-west-1
filters:
instance-state-name: running
register: ec2_info_one
tags:
- generate-files
- name: gather facts from us-west-2
ec2_remote_facts:
region: us-west-2
filters:
instance-state-name: running
register: ec2_info_two
tags:
- generate-files
# - name: debug ec2_info output
# debug: msg="{{ item.id }} {{ item.public_dns_name }}"
# with_items: "{{ ec2_info_one.instances }}"
# tags:
# - generate-files
# when: debug is defined
# - name: debug ec2_info output
# debug: msg="{{ item.id }} {{ item.public_dns_name }}"
# with_items: "{{ ec2_info_one.instances }}"
# tags:
# - generate-files
# when: debug is defined
- name: debug ec2_info_one output
debug: msg="{{ ec2_info_one.instances|pprint }}"
tags:
- generate-files
when: debug is defined
- name: debug ec2_info_one output
debug: msg="{{ ec2_info_one.instances|pprint }}"
tags:
- generate-files
when: debug is defined
- name: write the inventory file
template: src="./inv.j2" dest="{{ playbook_dir }}/mongo.inv"
tags:
- generate-files
- name: write delete runbook
template: src="./delete_instances.yml.j2" dest="{{ playbook_dir }}/delete_instances.yml"
tags:
- generate-files
- name: set fact for ec2_instances to info_one
set_fact: ec2_instances="{{ ec2_info_one.instances }}"
tags:
- generate-files
- name: set repset name to west1
set_fact: repset_name=west1
tags:
- generate-files
- name: debug ec2_instances
debug: msg="{{ ec2_instances|pprint }}"
tags:
- generate-files
- name: write group vars for mongo repset group
template: src="./group_vars.j2" dest="{{ playbook_dir }}/group_vars/west1"
tags:
- generate-files
- name: set fact for ec2_instances to info_two
set_fact: ec2_instances="{{ ec2_info_two.instances }}"
tags:
- generate-files
- name: set repset name to west2
set_fact: repset_name=west2
tags:
- generate-files
- name: write group vars for mongo repset group
template: src="./group_vars.j2" dest="{{ playbook_dir }}/group_vars/west2"
tags:
- generate-files