- hosts: localhost
connection: local
gather_facts: False
vars:
instance_count: 1
tasks:
- name: Create instances
local_action:
module: ec2
region: us-west-2
group_id: ****
keypair: ***
instance_type: t2.micro
image: ****
vpc_subnet_id: ****
count: "{{ instance_count }}"
wait: yes
register: ec2
- name: Add instances to inventory
add_host: name={{ item.private_ipi }} groups=new_instances
with_items: ec2.instances
- name: Wait for SSH
local_action: wait_for
host={{ item.private_ip }}
port=22
state=started
with_items: ec2.instances
- name: Configure
hosts: new_instances
gather_facts: True
remote_user: ***
sudo: True
roles:
- ***
- name: Wait for SSH
delegate_to: <bastion ip>
wait_for:
host={{ item.private_ip }}
port=22
state=started
with_items: ec2.instances
- hosts: localhost
#connection: local
gather_facts: False