# play\_hosts with serial includes only the hosts of the current batch

**URL:** <https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036>\
**Category:** Ansible Developer\
**Created:** [August 17, 2015, 3:53pm UTC](https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036 "2015-08-17T15:53:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivaylo\_Bratoev](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ivaylo\_Bratoev](https://forum.ansible.com/u/Ivaylo_Bratoev)\
**Post date:** [August 17, 2015, 3:53pm UTC](https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036/1 "2015-08-17T15:53:57Z")

</div>

When running a playbook with _serial_ the _play\_hosts_ variable includes the hosts just of the current batch. I think this is unexpected and can lead to various issues, especially with the cases where _play\_hosts_ is generally used (from docs: “This may be useful for filling out templates with multiple hostnames or for injecting the list into the rules for a load balancer”). Is this classified as a bug or known feature?

It seems this is related to the fact that _run\_once_ tasks in a _serial_ play are run once per host batch.

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [August 17, 2015, 4:09pm UTC](https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036/2 "2015-08-17T16:09:26Z")

</div>

I had situations when this proved useful and situations when this proved annoying 🙂 i’d love a finer control on this.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [August 17, 2015, 9:45pm UTC](https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036/3 "2015-08-17T21:45:13Z")

</div>

Yeah, I did not account for 'serial' when i added this, but we want to  
add 2 vars to reflect with and without serial behaviors.

---

<div class="post-metadata">

**Author:** ![Ivaylo\_Bratoev](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ivaylo\_Bratoev](https://forum.ansible.com/u/Ivaylo_Bratoev)\
**Post date:** [August 18, 2015, 9:50am UTC](https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036/4 "2015-08-18T09:50:43Z")

</div>

Thanks for the answer Brian,  
2 vars sounds like a good solution. Do you want me to open a GitHub issue for that? Would you accept a PR for that?

I was thinking a bit about naming the variables and here are some thoughts:  
I see _play\_hosts_ is being replaced by _ansible\_play\_hosts_ but _ansible\_play\_hosts_ is not documented and (hopefully) not widely used. So what do you think about these names:  
_ansible\_play\_hosts -_ all hosts in the play;  
\*ansible\_play\_batch\_hosts (\*or _ansible\_serial\_batch\_hosts_ or _ansible\_batch\_hosts)_ - all hosts in the current play batch.

Additionally, what do you think about the _run\_once_ issue - together with _serial run\_once_ runs once for each batch which again is unexpected? In the general case this is not a critical issue as executing _run\_once_ multiple times should work fine if your task is truly idempotent. In the same time, it is good to be able to run a task once _really_ per play; not per batch. You never know how Ansible can be (mis)used 😉

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [August 18, 2015, 4:17pm UTC](https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036/5 "2015-08-18T16:17:42Z")

</div>

run\_once is per batch and was always intended that way, as per naming  
the vars, I believe there is already some code doing that, need to x2  
check.

---

<div class="post-metadata">

**Author:** ![Marc\_Abramowitz](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marc\_Abramowitz](https://forum.ansible.com/u/Marc_Abramowitz)\
**Post date:** [November 26, 2015, 5:37am UTC](https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036/6 "2015-11-26T05:37:31Z")

</div>

Did these variables ever get implemented? My googling for ansible\_play\_hosts found almost nothing.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 26, 2015, 6:20am UTC](https://forum.ansible.com/t/play-hosts-with-serial-includes-only-the-hosts-of-the-current-batch/19036/7 "2015-11-26T06:20:03Z")

</div>

ansible\_play\_hosts is in the code base, but we never assign it, so not  
yet implemented, though the intention was there.
