# help w/ add\_host

**URL:** <https://forum.ansible.com/t/help-w-add-host/13531>\
**Category:** Ansible Project\
**Created:** [September 23, 2013, 9:01am UTC](https://forum.ansible.com/t/help-w-add-host/13531 "2013-09-23T09:01:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [September 23, 2013, 9:01am UTC](https://forum.ansible.com/t/help-w-add-host/13531/1 "2013-09-23T09:01:55Z")

</div>

In trying to wrangle my inventory to be more dynamic, I’ve come to find group\_by and add\_hosts. group\_by seems to work well, but I’m having trouble understanding why add\_host seems to only add a single host to a new group: it’s always the first host in the list.

When I use my recently created group names (from a group\_by) in a new playbook within the same run, my test remote echo works as expected, but add\_hosts is only called against a single host (always the first host in my inventory).

playbook and output here: [https://gist.github.com/davidbirdsong/6668127](https://gist.github.com/davidbirdsong/6668127)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 23, 2013, 11:44am UTC](https://forum.ansible.com/t/help-w-add-host/13531/2 "2013-09-23T11:44:52Z")

</div>

Using add\_host inside a host loop is not intended.

It’s intended for local plays that are doing machine provisioning, to add machines to inventory not yet picked up by an inventory script.

Use group\_by instead and you’ll get what you want.

I should also point out your “when” statement:
