Using when and not

25 views
Skip to first unread message

Matt Hughes

unread,
Dec 9, 2014, 5:21:49 PM12/9/14
to ansible...@googlegroups.com
I have a task to copy two different versions of the same file:

- name: Copy Version A
  copy
: ...
 
when: useCopyA

- name: Copy Version B
  copy
: ...
 
when: not useCopyA



For a playbook that has useCopyA defined as false, Ansible is skipping both tasks. 

If I replace "not useCopyA" with "not false", "Copy Version B" successfully executes with either OK or Changed, so 'not' works as I would expect.  I have 'useCopyA' defined as false in my defaults/main.yml.  It is only defined as true in one inventory which I am not using.  Any idea on what could be going wrong here?

Michael Peters

unread,
Dec 9, 2014, 5:47:55 PM12/9/14
to ansible...@googlegroups.com
There was a bug in ansible where when a variable foo is the string
"false" it interprets both "foo" and "not foo" as true.

https://github.com/ansible/ansible/issues/8629

But this bug is for an old version of ansible. Which version are you using?
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/3423dba6-2c6e-46f4-8685-fbe9e9ed95bb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Matt Hughes

unread,
Dec 9, 2014, 6:35:18 PM12/9/14
to ansible...@googlegroups.com
Using 1.7.3. I don't quote false or true anywhere; just using literal value.
> You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/8Ty9NhhGBlE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJQqANdF%3D71nmpmmBmpO1q5dW55PCym4V-gZotM%3DSNChFF74cw%40mail.gmail.com.

Toshio Kuratomi

unread,
Dec 9, 2014, 6:54:12 PM12/9/14
to ansible...@googlegroups.com
On Tue, Dec 9, 2014 at 3:35 PM, Matt Hughes <hughe...@gmail.com> wrote:
> Using 1.7.3. I don't quote false or true anywhere; just using literal value.
>
It's probably the bug Michael mentions. Due to playbooks going
through both yaml and jinja and sometimes variabels going through
jinja multiple times, things sometimes end up as strings instead of
the value you expect. One workaround that helps in many cases is to
use the jinja bool filter:

useCopyA|bool

-Toshio
Reply all
Reply to author
Forward
0 new messages