boto (2.40.0) ansible 2.0.2.0
When running this and trying to add multiple hosts to a new group for in memory inventory it only adding the first ec2 instance. On the wait for ssh task it does wait for all ec2 instances just not on the add host task.
- hosts: ec2_instances
connection: local
gather_facts: true
tasks:
- name: Launch Instance
ec2:
group_id: "{{ hostvars[inventory_hostname].group_id }}"
count: 1
instance_type: 't2.micro'
image: "{{ hostvars[inventory_hostname].image }}"
wait: true
region: 'us-east-1'
keypair: "{{ key_pair }}"
vpc_subnet_id: "{{ priv_subnet }}"
instance_tags: "{{ hostvars[inventory_hostname].tags }}"
register: ec2
- name: Wait for SSH
wait_for:
host: "{{ item.private_ip }}"
port: 22
delay: 10
timeout: 320
state: started
with_items: "{{ ec2.instances }}"
- name: Add hosts group temporary inventory group
add_host: name={{ item.private_ip }} groups=dynamic_hosts
with_items: "{{ ec2.instances }}"
- hosts: dynamic_hosts
gather_facts: yes
sudo: yes
roles:
- ansible-hostname-master