forked from thisdavejohnson/sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo-aws-relaunch.yml
103 lines (88 loc) · 2.79 KB
/
demo-aws-relaunch.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
---
- name: gather facts
hosts: all
gather_facts: true
vars_files:
- group_vars/all
tasks:
- name: gather facts
ec2_facts:
- name: terminate hosts
hosts: all
connection: local
tasks:
- name: terminate EC2 hosts
ec2: >
region="{{ ec2_region }}"
instance_ids="{{ item }}"
state=absent
wait=True
with_items: hostvars[inventory_hostname]['ansible_ec2_instance_id']
- name: launch hosts
hosts: localhost
connection: local
gather_facts: False
tasks:
#Provision some instances:
- name: Launch webserver instances
ec2: >
access_key="{{ ec2_access_key }}"
secret_key="{{ ec2_secret_key }}"
keypair="{{ ec2_keypair }}"
group="{{ ec2_security_group }}"
type="{{ ec2_instance_type }}"
image="{{ ec2_image }}"
region="{{ ec2_region }}"
instance_tags="{'ansible_group':'webservers', 'type':'{{ ec2_instance_type }}', 'group':'{{ ec2_security_group }}', 'Name':'demo-dj-web'}"
count="{{ ec2_instance_count }}"
wait=true
register: ec2
- name: Launch database instance
ec2: >
access_key="{{ ec2_access_key }}"
secret_key="{{ ec2_secret_key }}"
keypair="{{ ec2_keypair }}"
group="{{ ec2_security_group }}"
type="{{ ec2_instance_type }}"
image="{{ ec2_image }}"
region="{{ ec2_region }}"
instance_tags="{'ansible_group':'dbservers', 'type':'{{ ec2_instance_type }}', 'group':'{{ ec2_security_group }}', 'Name':'demo-dj-db'}"
count="1"
wait=true
register: ec2
- name: Launch load balancing instance
ec2: >
access_key="{{ ec2_access_key }}"
secret_key="{{ ec2_secret_key }}"
keypair="{{ ec2_keypair }}"
group="{{ ec2_security_group }}"
type="{{ ec2_instance_type }}"
image="{{ ec2_image }}"
region="{{ ec2_region }}"
instance_tags="{'ansible_group':'lbservers', 'type':'{{ ec2_instance_type }}', 'group':'{{ ec2_security_group }}', 'Name':'demo-dj-haproxy'}"
count="1"
wait=true
register: ec2
- name: Launch monitoring instance
ec2: >
access_key="{{ ec2_access_key }}"
secret_key="{{ ec2_secret_key }}"
keypair="{{ ec2_keypair }}"
group="{{ ec2_security_group }}"
type="{{ ec2_instance_type }}"
image="{{ ec2_image }}"
region="{{ ec2_region }}"
instance_tags="{'ansible_group':'monitoring', 'type':'{{ ec2_instance_type }}', 'group':'{{ ec2_security_group }}', 'Name':'demo-dj-nagios'}"
count="1"
wait=true
register: ec2
- name: Wait for SSH to come up
local_action: wait_for host={{ item.public_dns_name }}
port=22 delay=60 timeout=320 state=started
with_items: ec2.instances
- name: Sync Tower inventory
connection: local
command: tower-cli group sync --monitor --timeout 10 3
ignore_errors: true
tags:
- sync