# Using when and not

**URL:** <https://forum.ansible.com/t/using-when-and-not/17003>\
**Category:** Ansible Project\
**Created:** [December 9, 2014, 10:21pm UTC](https://forum.ansible.com/t/using-when-and-not/17003 "2014-12-09T22:21:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Hughes](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Matt\_Hughes](https://forum.ansible.com/u/Matt_Hughes)\
**Post date:** [December 9, 2014, 10:21pm UTC](https://forum.ansible.com/t/using-when-and-not/17003/1 "2014-12-09T22:21:49Z")

</div>

I have a task to copy two different versions of the same file:

`

- name: Copy Version A  
copy: …  
when: useCopyA

- name: Copy Version B  
copy: …  
when: not useCopyA

`

For a playbook that has useCopyA defined as false, Ansible is skipping both tasks.

If I replace “not useCopyA” with “not false”, “Copy Version B” successfully executes with either OK or Changed, so ‘not’ works as I would expect. I have ‘useCopyA’ defined as false in my defaults/main.yml. It is only defined as true in one inventory which I am not using. Any idea on what could be going wrong here?

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [December 9, 2014, 10:47pm UTC](https://forum.ansible.com/t/using-when-and-not/17003/2 "2014-12-09T22:47:51Z")

</div>

There was a bug in ansible where when a variable foo is the string  
"false" it interprets both "foo" and "not foo" as true.

[https://github.com/ansible/ansible/issues/8629](https://github.com/ansible/ansible/issues/8629)

But this bug is for an old version of ansible. Which version are you using?

---

<div class="post-metadata">

**Author:** ![Matt\_Hughes](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Matt\_Hughes](https://forum.ansible.com/u/Matt_Hughes)\
**Post date:** [December 9, 2014, 11:35pm UTC](https://forum.ansible.com/t/using-when-and-not/17003/3 "2014-12-09T23:35:13Z")

</div>

Using 1.7.3. I don't quote false or true anywhere; just using literal value.

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [December 9, 2014, 11:54pm UTC](https://forum.ansible.com/t/using-when-and-not/17003/4 "2014-12-09T23:54:09Z")

</div>

It's probably the bug Michael mentions. Due to playbooks going  
through both yaml and jinja and sometimes variabels going through  
jinja multiple times, things sometimes end up as strings instead of  
the value you expect. One workaround that helps in many cases is to  
use the jinja bool filter:

useCopyA\>bool

-Toshio
