Hi all,
I’m trying to figure out why the expression “false and (var is undefined)”, when ‘var’ has the value of an undefined variable, returns true. Here it is an example:
-
hosts: localhost
vars:
g: “{{ z }}”
is_false_var: false
tasks: -
debug: “msg=‘this must not be shown’”
when: (is_false_var) and (b is undefined)
ignore_errors: yes -
debug: “msg=‘this must not be shown’”
when: (is_false_var) and (g is undefined)
ignore_errors: yes -
debug: “msg=‘this must not be shown’”
when: (is_false_var) and false
ignore_errors: yes -
debug: “msg=‘this must not be shown’”
when: (is_false_var) and true
ignore_errors: yes -
debug: “msg={{ is_false_var and g is undefined }}”
ignore_errors: yes
That returns:
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [debug] *******************************************************************
skipping: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
“msg”: “this must not be shown”
}
TASK [debug] *******************************************************************
skipping: [localhost]
TASK [debug] *******************************************************************
skipping: [localhost]
TASK [debug] *******************************************************************
fatal: [localhost]: FAILED! => {“failed”: true, “msg”: “{{ z }}: ‘z’ is undefined”}
…ignoring
PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
Any ideas or thoughts about the avobe?
Thanks!