play_hosts with serial includes only the hosts of the current batch

681 views
Skip to first unread message

Ivaylo Bratoev

unread,
Aug 17, 2015, 11:53:58 AM8/17/15
to Ansible Development
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.

Hagai Kariti

unread,
Aug 17, 2015, 12:09:40 PM8/17/15
to Ivaylo Bratoev, Ansible Development

I had situations when this proved useful and situations when this proved annoying :) i'd love a finer control on this.


On Mon, Aug 17, 2015, 18:54 Ivaylo Bratoev <ivaylo....@gmail.com> wrote:
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Aug 17, 2015, 5:45:14 PM8/17/15
to Hagai Kariti, Ivaylo Bratoev, Ansible Development
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.


--
Brian Coca

Ivaylo Bratoev

unread,
Aug 18, 2015, 5:50:43 AM8/18/15
to Ansible Development, hka...@gmail.com, ivaylo....@gmail.com
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 ;)

Brian Coca

unread,
Aug 18, 2015, 12:17:44 PM8/18/15
to Ivaylo Bratoev, Ansible Development, Hagai Kariti
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.



--
Brian Coca

Marc Abramowitz

unread,
Nov 26, 2015, 12:37:32 AM11/26/15
to Ansible Development
Did these variables ever get implemented? My googling for ansible_play_hosts found almost nothing.

Brian Coca

unread,
Nov 26, 2015, 1:20:04 AM11/26/15
to Marc Abramowitz, Ansible Development
ansible_play_hosts is in the code base, but we never assign it, so not
yet implemented, though the intention was there.


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages