Hi,
We've encountered a few things which worked in 1.1 which don't work in
1.2. Most of them are fairly minor but I'm a bit concerned about other
things.
So I've been auditing our playbooks looking for potential trouble spots.
I have this conditional
only_if: 'is_set("${volumes}") and "${host_is_up.rc}" != "0"'
Which says "only if the host wasn't up in an earlier task and if the
variable 'volumes' is defined - then it will run that task.
I have tested it and the above works on 1.2 - but I'm aware that
only_if is, perhaps undesirable.
so my question - how would I port the above conditional to a when-based
world?
Thanks,
-sv
This:
only_if: ‘is_set(“${volumes}”) and “${host_is_up.rc}” != “0”’
Becomes:
when: volumes is defined and host_is_up.rc != 0
Clearly a huge improvement.
I do concur that listification of legacy template strings in 1.2 is not optimal in all cases, but we had to make the cutover somehow, and I’m hugely pleased by the new ways looking so much cleaner.
Michael, Thank you!
That is much easier to read, I concur. I just wasn't sure how to do
that. Is there a good example in the docs that i'm missing for compound
when statements?
thanks,
-sv
Don’t think so.
I’d welcome upgrades!
Basically anything to “when” is any expression in Jinja2 that evaluates with to True/False, the {{ and }} are just put around it automatically by Ansible. So it’s more or less Python, but not quite 100%.