Single when for multiple tasks

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.

You’re looking for parameterized roles. Put the tasks in a role, call the role conditionally when the criteria is met.

http://docs.ansible.com/playbooks_conditionals.html#applying-when-to-roles-and-includes

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.