# Unexpected evaluation of condition in 'when' statement

**URL:** <https://forum.ansible.com/t/unexpected-evaluation-of-condition-in-when-statement/22343>\
**Category:** Ansible Project\
**Created:** [August 22, 2016, 2:09pm UTC](https://forum.ansible.com/t/unexpected-evaluation-of-condition-in-when-statement/22343 "2016-08-22T14:09:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfredo\_M](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alfredo\_M](https://forum.ansible.com/u/Alfredo_M)\
**Post date:** [August 22, 2016, 2:09pm UTC](https://forum.ansible.com/t/unexpected-evaluation-of-condition-in-when-statement/22343/1 "2016-08-22T14:09:42Z")

</div>

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!
