Can somebody explain the new cleaned up variables? Maybe add something to the docs...
The new docs only mention when:, and I have a case that works with:
when_string: sometask.rc != 0
but I cannot figure out the right incantation of "when:" to make it work...
Thanks.
In 1.2, there is no need for “when_*” anymore. The new way is simply:
when: sometask.rc != 0
Still compatible for legacy reasons, since that was legal in 1.1:
when_integer: ${sometask.rc} != 0
Note that the “.rc” is a integer, not a string, so when_string will not work unless you quoted the 0, like:
when_integer: ${sometask.rc} != ‘0’
As I agree both of these forms are terrible (a result of fighting the inclusion of Jinja2 in Ansible for too long, I think!), that’s the reason for the new unified “when” simplicity.
The expression given to when is any Python expression legal to Jinja2 (so no list comprehensions) and is actually evaluated by the template Engine, but {{ foo }} style dereferences are unnecessary to keep things clean.
Since this is so much cleaner, the 1.2 docs only mention these forms, so folks can start standardizing on them.
I still have to update examples/playbooks/* in the source checkout do to the same.
I found the issue. I had a dash in my variable name. This worked fine with "when_string", but not with "when".
Yep, dashes shouldn’t be used in variable names.
We should document this and consider enforcing it with at least a warning.
What are the exact restrictions?
Letter, number, undersign? Any other acceptable characters?
Letter number underscore, starts with letter.
Things valid in Jinja2 need to be valid Python variables, which is pretty much the rule for most programming systems (some languages may have different rules but I can’t recall any offhand)