# evaluating a variable value as boolean

**URL:** <https://forum.ansible.com/t/evaluating-a-variable-value-as-boolean/30754>\
**Category:** Ansible Project\
**Created:** [July 11, 2019, 12:34pm UTC](https://forum.ansible.com/t/evaluating-a-variable-value-as-boolean/30754 "2019-07-11T12:34:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashank\_Dutt\_Jha](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Shashank\_Dutt\_Jha](https://forum.ansible.com/u/Shashank_Dutt_Jha)\
**Post date:** [July 11, 2019, 12:34pm UTC](https://forum.ansible.com/t/evaluating-a-variable-value-as-boolean/30754/1 "2019-07-11T12:34:31Z")

</div>

I have defined variable  
happened: true

When am trying to use this variable in task in conditional when clause it failed  
when: {{happened}} | bool == true it gives error.

what is the correct syntax to use it?

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [July 12, 2019, 6:53am UTC](https://forum.ansible.com/t/evaluating-a-variable-value-as-boolean/30754/2 "2019-07-12T06:53:15Z")

</div>

Hello Shashank,

This statement is getting failed because you didn’t use double quotes (" ") in your command.  
The correct syntax to use this statement is:

`when: "{{happened}} | bool == true"`

Thanks  
Soniya

---

<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:** [July 15, 2019, 3:16pm UTC](https://forum.ansible.com/t/evaluating-a-variable-value-as-boolean/30754/3 "2019-07-15T15:16:56Z")

</div>

conditionals already assume {{ }} context, so unless you are  
specifically aiming at double interpolation `when: happened|bool` is  
all you need
