-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-ec2-instance.yml
42 lines (39 loc) · 1.12 KB
/
create-ec2-instance.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
---
- hosts: all
connection: local
tasks:
- name: creating ec2 node
tags: provisioning
action:
module: ec2
aws_access_key: "{{ vault_aws_access_key }}"
aws_secret_key: "{{ vault_aws_secret_key }}"
zone: "{{ zone }}"
image: "{{ image }}"
instance_type: "{{ instance_type }}"
state: present
region: "{{ region }}"
key_name: "{{ sshkey }}"
vpc_subnet_id: "{{ subnet }}"
group: "{{ security_group }}"
wait: true
instance_tags:
Name: "{{ env }}-{{ role }}"
Roles: "{{ role }}"
Project: "{{ project }}"
Stages: "{{ env }}"
register: ec2
# Use with_items to add each instances public IP to a new hostgroup for use in the next play.
- name: Add new instance to host group
add_host:
hostname: "{{ item.public_dns_name }}"
groupname: "{{ inventory_hostname }}"
with_items: ec2.instances
- name: Waiting for SSH to boot by checking the ssh port
wait_for:
host: "{{ item.public_dns_name }}"
port: 22
delay: 10
timeout: 120
state: started
with_items: ec2.instances