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





On Sun, Aug 31, 2014 at 2:11 AM, Olivier Javaux <[email protected]>
wrote:

> 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
> 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!
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/55b02402-0d36-44b7-9ec6-2c2554a3e44c%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/55b02402-0d36-44b7-9ec6-2c2554a3e44c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwb%2BtfzAw5Y7fJ3m-fY69iPghp8g0k1VVxr5xfpc7LKhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to