Ansible 1.2 - conditionals

So, some things.

“when_foo” and “only_if” are the way things used to work. There’s the new “when” in 1.2 that is intended to simplify everything. The when_boolean stuff is something you should not be using in 1.2, because the new keyword is “when”. The old ways were too messy and confusing, so now we have something that evaluates Jinja2 conditionals just like templates have. Note that it’s not raw Python, it’s evaluated by Jinja2, so the ‘any’ function isn’t available (neither is os.path.unlink :))

Thus what you want is basically just:

when: ‘gitservers-pr’ in group_names or ‘gitservers-st’ in group_names

However, really, if you think about it, what’s a group selector? “Hosts!”. That already exists in playbooks.

So it is really the intent of Ansible that you never have to write conditionals like this. You should not need to, because you are allowed multiple plays.

Suppose you want to talk to things in group “foo” that are in ‘gitservers-pr’ and ‘gitservers-st’. That’s just like this:

  • hosts: gitservers-pr:gitservers-st:&mandatory-other-group

Or if you just wanted to cleanly say “just things in those two groups”, it’s simpler:

  • hosts: gitservers-pr:gitservers-st