# ansible add\_host module is not adding multiple hosts

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

<div class="post-metadata">

**Author:** ![Eric\_S1](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@Eric\_S1](https://forum.ansible.com/u/Eric_S1)\
**Post date:** [May 18, 2016, 3:14pm UTC](https://forum.ansible.com/t/ansible-add-host-module-is-not-adding-multiple-hosts/21480/1 "2016-05-18T15:14:42Z")

</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

```
