New in latest git -- Being able to reuse conditionals in playbooks

New syntax upgrade in latest git – I’ve made it possible to reuse conditionals (only_if) by declaring them in the vars (or vars_files) section. Here is an example:

https://github.com/ansible/ansible/blob/master/examples/playbooks/playbook4.yml

You can put them in vars, but you can also use ‘vars_files’ (as mentioned elsewhere in the docs/examples).

For instance, you could define all of your conditionals in:

vars_files:

  • ‘vars/common.yml’

And easily reuse them between playbooks. (i.e. you can define “is_centos” or “is_virtualized” once and only once)

I’ll update the docs to reflect this new capability shortly.

I think this does a lot to improving the syntax of “only_if”, and should help prove that we can keep the task list short without
having to nest it… which in the end means really simple to read playbooks.

–Michael