# gather further host list to run next play

**URL:** <https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067>\
**Category:** Ansible Project\
**Created:** [July 4, 2013, 3:21pm UTC](https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067 "2013-07-04T15:21:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mastermind](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mastermind](https://forum.ansible.com/u/mastermind)\
**Post date:** [July 4, 2013, 3:21pm UTC](https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067/1 "2013-07-04T15:21:10Z")

</div>

Hi,

i guys, is there a possibility to do stuff like the following?

my playbook:

---

<div class="post-metadata">

**Author:** ![Timothy\_Gerla](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Timothy\_Gerla](https://forum.ansible.com/u/Timothy_Gerla)\
**Post date:** [July 4, 2013, 3:24pm UTC](https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067/2 "2013-07-04T15:24:45Z")

</div>

Hi,

Take a look at the "add\_host" module which could probably be used to  
achieve this. Hope this helps!

-Tim

---

<div class="post-metadata">

**Author:** ![mastermind](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mastermind](https://forum.ansible.com/u/mastermind)\
**Post date:** [July 4, 2013, 3:27pm UTC](https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067/3 "2013-07-04T15:27:31Z")

</div>

Cool! I didnt find it before… it seems that this module really helps me out

---

<div class="post-metadata">

**Author:** ![mastermind](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mastermind](https://forum.ansible.com/u/mastermind)\
**Post date:** [July 4, 2013, 4:49pm UTC](https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067/4 "2013-07-04T16:49:50Z")

</div>

Hi once again,

maybe some can give me one more hint, what my failure here:

---

<div class="post-metadata">

**Author:** ![Timothy\_Gerla](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Timothy\_Gerla](https://forum.ansible.com/u/Timothy_Gerla)\
**Post date:** [July 4, 2013, 4:53pm UTC](https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067/5 "2013-07-04T16:53:03Z")

</div>

Do you have any hosts in [all] right now? You need at least one,  
probably "localhost". So I'd try something like this:

inventory:

[local]  
localhost

and then the play:

- hosts: local  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: add hosts to new group  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: add\_host name=10.1.93.171 groups=just\_created

...

Your second play looks fine.

Hope this helps,

-Tim

---

<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:** [July 4, 2013, 6:28pm UTC](https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067/6 "2013-07-04T18:28:16Z")

</div>

Yeah be aware hosts:all is not how you want to use “group\_by”, more like “hosts:localhost”. Won’t hurt anything, but you really want to only run that step once, not once per host.

And you want to make sure that localhost is defined in inventory too.

---

<div class="post-metadata">

**Author:** ![mastermind](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mastermind](https://forum.ansible.com/u/mastermind)\
**Post date:** [July 4, 2013, 8:46pm UTC](https://forum.ansible.com/t/gather-further-host-list-to-run-next-play/13067/7 "2013-07-04T20:46:22Z")

</div>

Hi Michael, hi Tim,

you’re right, host: all isnt good, but i limited the playbook call to one single host with -l :)… Anyways, yes i got an inventory with one group (all) and about 4000 machines.  
The machine in my test play (10.1.93.171), exists also in there.

Now i moved my inventory script in /etc/ansible/hosts and have written only one host (localhost) in there as Tim suggested. same result:

lborchard@smo001:~/ansible\_work$ ansible-playbook -l localhost count-tst.yml -vv

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 REMOTE\_MODULE setup  
ok: [localhost]

TASK: [add hosts to new group] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
creating host via ‘add\_host’: hostname=10.1.93.171  
added host to group via add\_host module: just\_created  
changed: [localhost] =\> {“changed”: true, “new\_groups”: [“just\_created”], “new\_host”: “10.1.93.171”}

PLAY [just\_created] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: no hosts matched

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=2 changed=1 unreachable=0 failed=0

lborchard@smo001:~/ansible\_work$ cat /etc/ansible/hosts  
[all]  
localhost

Dont get it… ☹  
lborchard@smo001:~/ansible\_work$ ansible --version  
ansible 1.1
