# ansible add\_host module is not adding multiple hosts

**URL:** <https://forum.ansible.com/t/ansible-add-host-module-is-not-adding-multiple-hosts/21478>\
**Category:** Ansible Project\
**Created:** [May 18, 2016, 2:16pm UTC](https://forum.ansible.com/t/ansible-add-host-module-is-not-adding-multiple-hosts/21478 "2016-05-18T14:16:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric\_skaggs](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@eric\_skaggs](https://forum.ansible.com/u/eric_skaggs)\
**Post date:** [May 18, 2016, 2:16pm UTC](https://forum.ansible.com/t/ansible-add-host-module-is-not-adding-multiple-hosts/21478/1 "2016-05-18T14:16:16Z")

</div>

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.

```auto
- 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

```

This email communication (including any attachments) contains information from Answers Corporation or its affiliates that is confidential and may be privileged. The information contained herein is intended only for the use of the addressee(s) named above. If you are not the intended recipient (or the agent responsible to deliver it to the intended recipient), you are hereby notified that any dissemination, distribution, use, or copying of this communication is strictly prohibited. If you have received this email in error, please immediately reply to sender, delete the message and destroy all copies of it. If you have questions, please email [legal@answers.com](mailto:legal@answers.com).

If you wish to unsubscribe to commercial emails from Answers and its affiliates, please go to the Answers Subscription Center [http://campaigns.answers.com/subscriptions](http://campaigns.answers.com/subscriptions) to opt out. Thank you.
