Unexpected evaluation of condition in 'when' statement

14 views
Skip to first unread message

Alfredo M

unread,
Aug 22, 2016, 10:09:42 AM8/22/16
to Ansible Project
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!
Reply all
Reply to author
Forward
0 new messages