-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMT_create_env.yml
44 lines (42 loc) · 1.23 KB
/
IMT_create_env.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
---
- name: Create an ec2 instance
hosts: localhost
gather_facts: no
vars_files:
- group_vars/vars/imt_env.dev
tasks:
- name: Get the latest AMZ AMI-ID
ec2_ami_find:
name: "amzn-ami-hvm*-gp2"
owner: "{{ owner_id_amazon }}"
region: "{{ region }}"
sort: creationDate
sort_order: descending
sort_end: 1
register: ami_find
- name: Launch AMZ ec2 instance
ec2:
key_name: "{{ key_name }}"
instance_type: "{{ instance_type }}"
image: "{{ ami_find.results[0].ami_id }}"
wait: true
region: "{{ region }}"
vpc_subnet_id: "{{ vpc_subnet_id }}"
group: "{{ security_group }}"
assign_public_ip: yes
instance_tags:
Name: "{{ instance_tag }}"
register: ec2
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname=launched_instance
with_items: '{{ec2.instances}}'
- name: Wait for SSH to come up
wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=90 state=started
with_items: '{{ec2.instances}}'
- name: Provision stuff
hosts: launched_instance
user: ec2-user
become: true
roles:
- common
- docker