-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2-creation.yml
54 lines (50 loc) · 1.33 KB
/
ec2-creation.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
- name: Create a sandbox instance
hosts: localhost
gather_facts: False
vars:
keypair: deepak_ubuntu
instance_type: t2.micro
security_group: default
image: ami-d783a9b8
region: ap-south-1
tasks:
- name: Launch instance
ec2:
key_name: "{{ keypair }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
wait: true
region: "{{ region }}"
vpc_subnet_id: subnet-af1b17e2
assign_public_ip: yes
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: launched
#become: True
#gather_facts: True
#roles:
#- my_awesome_role
#- my_awesome_test
- name: Terminate instances
hosts: localhost
connection: local
tasks:
- name: Terminate instances that were previously launched
ec2:
region: ap-south-1
state: 'absent'
instance_ids: '{{ ec2.instance_ids }}'