Single when for multiple tasks

94 views
Skip to first unread message

Stephan S.

unread,
Apr 10, 2014, 4:38:07 AM4/10/14
to ansible...@googlegroups.com
Hello.

I would like to know if it is possible to enclose multiple tasks with one when clause.
I am trying to avoid to use the same when statement for all of my tasks in the same playbook.

Furthermore, as a requirement is that the above should be implemented while using a single playbook.
So all of the statements while also the single when clause that controls those tasks should be in the same
playbook.

Is something like this possible?

Thank you in advance.

Paul Durivage

unread,
Apr 10, 2014, 12:16:05 PM4/10/14
to ansible...@googlegroups.com
You're looking for parameterized roles.  Put the tasks in a role, call the role conditionally when the criteria is met.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5470ce46-855e-42c8-875a-af68db46ea5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
Apr 15, 2014, 4:56:36 PM4/15/14
to ansible...@googlegroups.com
Yep, this will do -- though will generate somewhat verbose "skipped" output, or you could also use the group_by module to create an in-memory group of just the hosts where the conditions are true.

The first (the roles trick) is the cleaner playbook, the second is cleaner output.


Reply all
Reply to author
Forward
0 new messages