-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook-old.yml
71 lines (65 loc) · 1.57 KB
/
playbook-old.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
# demo1.yml
- name: Start sandbox instances
hosts: localhost
connection: local
gather_facts: False
vars:
key_name: mbp
instance_type: t2.micro
security_group: test
image: ami-976152f2
region: us-east-2
tasks:
- name: Launch instance
ec2:
key_name: "{{ key_name }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
wait: true
region: "{{ region }}"
exact_count: 1
count_tag:
Name: Demo
instance_tags:
Name: Demo
register: ec2
- name: Add new instance to host group
add_host:
hostname: "{{ item.public_ip }}"
groupname: launched
with_items: "{{ ec2.instances }}"
- name: Wait for SSH to come up
wait_for:
host: "{{ item.public_dns_name }}"
port: 22
delay: 60
timeout: 320
state: started
with_items: "{{ ec2.instances }}"
- name: Configure instance(s)
hosts: all
remote_user: ec2-user
become: True
gather_facts: True
tasks:
- name: Install python setuptools and docker
yum:
name: "{{ item }}"
update_cache: yes
with_items:
- python-setuptools
- docker
- pip:
name: docker-py
- name: Terminate instances
hosts: localhost
connection: local
vars:
region: us-east-2
tasks:
- name: Terminate instances that were previously launched
ec2:
region: "{{ region }}"
state: 'absent'
instance_ids: '{{ ec2.instance_ids }}'