# It is unnecessary to use '{{' in conditionals...

**URL:** <https://forum.ansible.com/t/it-is-unnecessary-to-use-in-conditionals/16085>\
**Category:** Ansible Project\
**Created:** [August 31, 2014, 6:11am UTC](https://forum.ansible.com/t/it-is-unnecessary-to-use-in-conditionals/16085 "2014-08-31T06:11:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivier\_Javaux](https://avatars.discourse-cdn.com/v4/letter/o/3da27b/32.png) [@Olivier\_Javaux](https://forum.ansible.com/u/Olivier_Javaux)\
**Post date:** [August 31, 2014, 6:11am UTC](https://forum.ansible.com/t/it-is-unnecessary-to-use-in-conditionals/16085/1 "2014-08-31T06:11:29Z")

</div>

Hello,  
Still the warning “It is unnecessary to use ‘{{’ in conditionals”.  
I have read old posts on this subject and the ticket  
[https://github.com/ansible/ansible/issues/4582](https://github.com/ansible/ansible/issues/4582)  
I am using latest devel release.  
But I don’t understand why I get this message and if I am using the good way of doing what I want.  
I have to make a lot of tasks under certain conditions.  
In order to simplify, I do something like this;

- shell: something  
register st
- set\_fact: flag=0
- set\_fact: flag=1  
when: cur\_sw.stdout == "something’
- shell: something else  
when: flag==1  
…

So, I use a fact as a boolean flag to skip or not following tasks.  
If flag==1, I execute the following tasks and then update again flag according to the result.  
And if still 1, I execute some other tasks.

My problem is that when I do:  
when: flag==1  
it does not work: it always skip the task.  
In order to have it to work, I have to do:  
when: “{{flag}}==1”  
But when I do that, I have the warning:  
It is unnecessary to use ‘{{’ in conditionals, leave variables in loop expressions bare.  
I can avoid the warning by doing:  
when: “1=={{flag}}”  
but it is only a poor trick!

Please, could you explain me why  
when: flag==1  
does not work?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 1, 2014, 6:05pm UTC](https://forum.ansible.com/t/it-is-unnecessary-to-use-in-conditionals/16085/2 "2014-09-01T18:05:02Z")

</div>

When you use set\_fact in a single line, it doesn’t know what type you mean:

set\_fact: flag=1

Thus you want either:

when: flag|int == 1

OR:

when: flag == ‘1’

otherwise, pass a dictionary to set\_fact, and types will be as you would expect:

set\_fact:  
flag: 1

---

<div class="post-metadata">

**Author:** ![Olivier\_Javaux](https://avatars.discourse-cdn.com/v4/letter/o/3da27b/32.png) [@Olivier\_Javaux](https://forum.ansible.com/u/Olivier_Javaux)\
**Post date:** [September 2, 2014, 8:47am UTC](https://forum.ansible.com/t/it-is-unnecessary-to-use-in-conditionals/16085/3 "2014-09-02T08:47:22Z")

</div>

Many thanks, that works.  
I understand better the type problem.
