# bool and string evaluation gives mixed result if using curly brackets

**URL:** <https://forum.ansible.com/t/bool-and-string-evaluation-gives-mixed-result-if-using-curly-brackets/26218>\
**Category:** Ansible Project\
**Created:** [December 7, 2017, 10:18am UTC](https://forum.ansible.com/t/bool-and-string-evaluation-gives-mixed-result-if-using-curly-brackets/26218 "2017-12-07T10:18:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [December 7, 2017, 10:18am UTC](https://forum.ansible.com/t/bool-and-string-evaluation-gives-mixed-result-if-using-curly-brackets/26218/1 "2017-12-07T10:18:04Z")

</div>

The snippet below evaluates to true, then false with myvar=false. How come? ansible version 2.2.1.0 on OSX High Sierra

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 7, 2017, 10:23am UTC](https://forum.ansible.com/t/bool-and-string-evaluation-gives-mixed-result-if-using-curly-brackets/26218/2 "2017-12-07T10:23:21Z")

</div>

You can't use double curly brackets in when, in when you are in template mode already so the double curly brackets is implied.

---

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [December 7, 2017, 11:04am UTC](https://forum.ansible.com/t/bool-and-string-evaluation-gives-mixed-result-if-using-curly-brackets/26218/3 "2017-12-07T11:04:42Z")

</div>

The problem is that when: “{{ something == ‘yes’ and myvar }}” yields the desired result e.g.:

ansible-playbook play.yml -c local -i 127.0.0.1, -e myvar=true -e something=“yes”

PLAY [do stuff with curlies] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [127.0.0.1]

I will go ahead and use “myvar | bool” everywhere as that too works.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 7, 2017, 11:30am UTC](https://forum.ansible.com/t/bool-and-string-evaluation-gives-mixed-result-if-using-curly-brackets/26218/4 "2017-12-07T11:30:46Z")

</div>

> The problem is that when: "{{ something == 'yes' and myvar }}" yields the  
> desired result e.g.:
> 
> ansible-playbook play.yml -c local -i 127.0.0.1, -e myvar=true -e  
> something="yes"  
> PLAY [do stuff with curlies]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> changed: [127.0.0.1]

That's just luck since Jinja doesn't support stacked curly brackets.

> I will go ahead and use "myvar | bool" everywhere as that too works.

Variables values on the command line become strings so you would need to filter it with bool or check for the actual string.
