-
Notifications
You must be signed in to change notification settings - Fork 0
/
amazon.yml
55 lines (49 loc) · 1.49 KB
/
amazon.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
---
- name: Create ad-hoc AWS EC2 Instances
hosts: localhost
connection: local
gather_facts: False
vars:
key_name: <key-pair-name>
instance_type: <ec2-instance-type-code>
instance_image: <ec2-instance-image>
instance_num: <number-of-spawned-instances>
region: <aws-region-code>
security_group: <custom-security-group>
vpc: <ec2-vpc-subnet-here>
aws_tag: <aws-instance-tags>
tasks:
- name: Launch specific ec2 instances
ec2:
key_name: "{{ key_name }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ instance_image }}"
wait: yes
region: "{{ region }}"
vpc_subnet_id: "{{ vpc }}"
assign_public_ip: yes
instance_tags:
type: "{{ aws_tag }}"
exact_count: "{{ instance_num }}"
count_tag:
type: "{{ aws_tag }}"
register: servers
- name: Add all new instance to host group for later use
add_host:
hostname: "{{ item.public_ip }}"
groups: launched
with_items: "{{ servers.instances }}"
- name: Wait for SSH on all instances to come up
wait_for:
host: "{{ item.public_dns_name }}"
port: 22
delay: 60
timeout: 320
state: started
with_items: "{{ servers.instances }}"
- name: Terminate instances that were previously launched
ec2:
region: "{{ region }}"
instance_ids: "{{ servers.instance_ids }}"
state: 'absent'