# when conditional failing to skip a task on string comparison (2.0)

**URL:** <https://forum.ansible.com/t/when-conditional-failing-to-skip-a-task-on-string-comparison-2-0/20275>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 19, 2016, 3:37pm UTC](https://forum.ansible.com/t/when-conditional-failing-to-skip-a-task-on-string-comparison-2-0/20275 "2016-01-19T15:37:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eduardo\_Esclapes\_Gim](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@Eduardo\_Esclapes\_Gim](https://forum.ansible.com/u/Eduardo_Esclapes_Gim)\
**Post date:** [January 19, 2016, 3:37pm UTC](https://forum.ansible.com/t/when-conditional-failing-to-skip-a-task-on-string-comparison-2-0/20275/1 "2016-01-19T15:37:55Z")

</div>

Hi there,

A task that shoud skip is running and failing. This is the task

> - name: Fail if project\_subtree\_path is set incorrectly  
> fail:  
> msg: “subtree is set to ‘{{ project\_subtree\_path }}’ but that path does not exist in the repo. Edit `subtree_path` for ‘{{ site }}’ in `sites.yml`.”  
> when: project\_subtree\_path != ‘False’ and not project\_subtree\_full\_path.stat.exists

And the error message indicates that the variable is indeed set to ‘False’

> FAILED! =\> {“changed”: false, “failed”: true, “msg”: “subtree is set to ‘False’ but that path does not exist in the repo. Edit `subtree_path` for ‘[sobiranialimentariapv.org](http://sobiranialimentariapv.org)’ in `sites.yml`.”}

Am I missing something on the 2.0 way of doing when?

I am running 2.0.0.1 on ubuntu 14.04

Thanks in advance

---

<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:** [January 19, 2016, 3:43pm UTC](https://forum.ansible.com/t/when-conditional-failing-to-skip-a-task-on-string-comparison-2-0/20275/2 "2016-01-19T15:43:02Z")

</div>

is it 'False' or False? they are different things, a better check that  
can deal with both is:

when: project\_subtree\_path|bool and not project\_subtree\_full\_path.stat.exists

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 19, 2016, 3:43pm UTC](https://forum.ansible.com/t/when-conditional-failing-to-skip-a-task-on-string-comparison-2-0/20275/3 "2016-01-19T15:43:32Z")

</div>

You are explicitly checking that project\_subtree\_path is the string value of “False”, and not the boolean False.

I would likely recommend making that part of the check look like:

when: project\_subtree\_path|bool and not project\_subtree\_full\_path.stat.exists

---

<div class="post-metadata">

**Author:** ![Eduardo\_Esclapes\_Gim](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@Eduardo\_Esclapes\_Gim](https://forum.ansible.com/u/Eduardo_Esclapes_Gim)\
**Post date:** [January 19, 2016, 4:11pm UTC](https://forum.ansible.com/t/when-conditional-failing-to-skip-a-task-on-string-comparison-2-0/20275/4 "2016-01-19T16:11:18Z")

</div>

Hi, thanks for your responses,

That variable is supposed to hold a string and ‘False’ meant that it was not applicable. Probably a bad choice.

I guess using an empty string would make more sense in this case, right?
