forked from wardviaene/ansible-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2.yml
36 lines (36 loc) · 1.04 KB
/
ec2.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
- name: Create a new instance
hosts: localhost
connection: local
gather_facts: False
vars:
keypair: ansible
instance_type: t2.micro
security_group: sg-ba9a5ede
image: ami-f95ef58a
region: eu-west-1
subnet: subnet-7a522c0d
groupname: webservers
tasks:
- name: Launch instance
ec2:
key_name: "{{ keypair }}"
group_id: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
wait: true
region: "{{ region }}"
vpc_subnet_id: "{{ subnet }}"
assign_public_ip: yes
register: ec2
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname={{ groupname }}
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 new instance
hosts: webservers
sudo: yes
remote_user: ubuntu
gather_facts: True
- include: nginx-ec2.yml