Tell me about it Leo, the documentation on this language is seriously lacking.
On Tuesday, April 7, 2015 at 12:54:01 AM UTC-7, Jialiang Liang wrote: > > I faced the same problem. > > I tried Nick Groenen's code and it doesn't work when the params is like > this: > ``` > foo: > ``` > in this case, foo is define and foo == none > > And it doesn't work when foo: ' ' > > This is what I came up with: > > not((foo is undefined) or (foo is none) or (foo|trim == '')) > > Not sure if there is any build-in function that implement similar logic. > > Cheers > > Leo Liang > > 在 2014年1月31日星期五 UTC+11下午10:58:17,Stephen Ryan写道: >> >> >> >> Best to explain with an example >> >> We have tasks setup like >> >> - name: do something >> shell: do task >> when: foo is defined >> >> This works perfectly for most situations however we have a number of >> places where we need to unset the variable to stop the command on certain >> hosts. Neither of the following work when set in the group vars and result >> in the task working. >> >> foo: >> foo: "" >> >> So my question is how would one normally unset a variable like this or >> correctly test for it. Jinja docs suggest its just an "if variable" [1], so >> "when: foo" but that doesn't work whenever the variable has a value >> >> fatal: [127.0.0.1] => error while evaluating conditional: foo >> >> The closest I've gotten is >> when: foo is defined and foo is string >> but this feels wrong and there is no reference to using an "is string" >> check in the ansible docs. >> >> [1] http://jinja.pocoo.org/docs/templates/#if >> > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d546481d-9127-4c2f-89c5-4a98e27d856b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
