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.
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.