# Inconsistent boolean handling of False

**URL:** <https://forum.ansible.com/t/inconsistent-boolean-handling-of-false/18583>\
**Category:** Ansible Project\
**Created:** [June 23, 2015, 4:31pm UTC](https://forum.ansible.com/t/inconsistent-boolean-handling-of-false/18583 "2015-06-23T16:31:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Si\_W](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Si\_W](https://forum.ansible.com/u/Si_W)\
**Post date:** [June 23, 2015, 4:31pm UTC](https://forum.ansible.com/t/inconsistent-boolean-handling-of-false/18583/1 "2015-06-23T16:31:44Z")

</div>

I have been struggling with booloean handling and read through [https://github.com/ansible/ansible/issues/8629](https://github.com/ansible/ansible/issues/8629) not sure if its fixed or I am just not getting the jist. If I run something like …

`

vars:  
foo: True  
bar: False  
foobar: ‘{{ foo and bar }}’

tasks:

- debug: msg=“If foo is True”  
when: foo

- debug: msg=“If bar is False”  
when: not bar

- debug: msg=“foobar is True”  
when: foobar

- debug: msg=“foobar is false”  
when: not foobar

- debug: msg=“foobar|bool is false”  
when: not foobar|bool

- debug:  
var=foobar

`

If I run the above I get

`  
PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [debug msg=“If foo is True”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “If foo is True”  
}

TASK: [debug msg=“If bar is False”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “If bar is False”  
}

TASK: [debug msg=“foobar is True”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [localhost]

TASK: [debug msg=“foobar is false”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [localhost]

TASK: [debug msg=“foobar|bool is false”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “foobar|bool is false”  
}

TASK: [debug var=foobar] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“var”: {  
“foobar”: “False”  
}  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=5 changed=0 unreachable=0 failed=0

`

Is this just expected behaviour due to mix of yaml and jinja2 it just seems messy having to work out when to use |bool ?

Cheers  
Si

`

`

---

<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:** [June 23, 2015, 5:56pm UTC](https://forum.ansible.com/t/inconsistent-boolean-handling-of-false/18583/2 "2015-06-23T17:56:11Z")

</div>

This bug should be fixed. Which version are you using? But even when  
it's fixed, the string "false" is a true value.

I do admit that "|bool" everywhere is kind of annoying, but it's the  
safest way to always make sure your context is correct.

---

<div class="post-metadata">

**Author:** ![Si\_W](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Si\_W](https://forum.ansible.com/u/Si_W)\
**Post date:** [June 24, 2015, 8:29am UTC](https://forum.ansible.com/t/inconsistent-boolean-handling-of-false/18583/3 "2015-06-24T08:29:51Z")

</div>

Running ansible 1.9.1. Maybe the booloean section in [https://docs.ansible.com/playbooks\_conditionals.html#the-when-statement](https://docs.ansible.com/playbooks_conditionals.html#the-when-statement) nees to reflect this and spent some time to figure this out?

Cheers,  
Si.
