I am not sure whether someone has come across this issue previously - trying to search the group for ‘when’ and ‘is defined’ did not yield me anything useful. So I am posting it as a new topic here.
I have encountered that in case I use ‘when:’ clause where I need to test whether one variable is set to ‘true’ and another one is defined, the following playbook triggers action even if the first variable is ‘false’:
According to the documentation when: takes a jinja 2 expression.
I don’t know the order of precedence in jinja 2, but
var1 and var2 is defined
could be read as
(var1 and var2) is defined
or
var1 and (var2 is defined)
I suspect that you are looking for the second one, but you MIGHT be getting the first. have you considered grouping the relevant parts so that you have
(var1) and (var2 is defined)
To me, that seems a lot clearer as to the intent.
Thanks for getting to the bottom of this and providing a working solution! Works as charm indeed! Jinja framework is crazy IMHO.
Adam: grouping does not help, I tried it before submitting my first request, as well as swapping the order.
The issue is solved, thank you! I wonder what is the process of altering documentation on docs.ansible.com, googling for it provided me a link which does not contain the text that is shown in the search preview.
Does submitting an issue to the Ansible repo sound like a proper idea?