# ansible when statement error

**URL:** <https://forum.ansible.com/t/ansible-when-statement-error/21877>\
**Category:** Ansible Project\
**Created:** [June 28, 2016, 2:02pm UTC](https://forum.ansible.com/t/ansible-when-statement-error/21877 "2016-06-28T14:02:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 28, 2016, 2:02pm UTC](https://forum.ansible.com/t/ansible-when-statement-error/21877/1 "2016-06-28T14:02:42Z")

</div>

```auto
---
- hosts: all
  gather_facts: no
  vars:
    XQWATCHER_GIT_IDENTITY: !!null

  tasks:
    - debug:
        msg: "Test Success"
      when: XQWATCHER_GIT_IDENTITY is defined

```

Getting this error when I run the playbook

```auto
ansible-playbook -i "localhost," test.yml -c local

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "The conditional check 'XQWATCHER_GIT_IDENTITY' failed. The error was: error while evaluating conditional (XQWATCHER_GIT_IDENTITY): 'abc' is undefined\n\nThe error appears to have been in '/Users/arbab/test-ansible/test.yml': line 8, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - debug:\n ^ here\n"}

```

---

<div class="post-metadata">

**Author:** ![Arbab\_Nazar](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Arbab\_Nazar](https://forum.ansible.com/u/Arbab_Nazar)\
**Post date:** [June 28, 2016, 2:04pm UTC](https://forum.ansible.com/t/ansible-when-statement-error/21877/2 "2016-06-28T14:04:05Z")

</div>

sorry about the error, here is the error:

fatal: [localhost]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘"XQWATCHER\_GIT\_IDENTITY" id defined’ failed. The error was: template error while templating string: expected token ‘end of statement block’, got ‘id’. String: {% if "XQWATCHER\_GIT\_IDENTITY" id defined %} True {% else %} False {% endif %}\n\nThe error appears to have been in ‘/Users/arbab/test-ansible/test.yml’: line 8, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - debug:\n ^ here\n”}

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 28, 2016, 2:07pm UTC](https://forum.ansible.com/t/ansible-when-statement-error/21877/3 "2016-06-28T14:07:12Z")

</div>

you error has ‘{% if "XQWATCHER\_GIT\_IDENTITY" id defined %}’, which seems to indicate you misspelled ‘is’ as ‘id’.
