All - I’m trying to dynamically set facts in a loop. (Long story short, for a list of keys, if the key isn’t defined, I want to replace the key with the value from a register variable.) I have a playbook that works, but it requires the use of {{ }} in a when: clause, and Ansible is complaining. Can anyone figure out how to rewrite the when: without {{ }} ?
gives error
The task includes an option with an undefined variable. The error was: No variable found with this name: no_existing_var
This means you need to put a string that you would never use as default, something like this
when: lookup('vars', item.key, default='the varible is not defined') == 'the varible is not defined'
This works but is not a very elegant solution as the test "is not defined"
my issue with 'vars' is that it is not templated for all values, it
was never meant for direct use and we don't even use internally
anymore and we hope to remove soon.
the `vars` lookup does template values correctly and was created for
that purpose.
vars lookup is not a very good substitute IMHO since it can't handle undefined variable very well.
So that leaves us with vars for the foreseeable future.