Today I needed to add a condition to a play in my playbook. If it is true, the tasks are executed.
I’d expect this intuitive code to work:
hosts:all
become:yes
when:
tasks:
…
Unfortunately, “when” is not a valid attribute of the play and I’m required to do it in a less intuitive way: e.g. replicate the when attribute for all tasks (worst solution), move all tasks to a single block of tasks and assign a when attribute to it or moving the play to a separate yaml and conditionally include it. All these solutions seem more cumbersome than just setting the when attribute to a play. Is there a reason why it is not supported?