Hi Adam, the logic you have there is the problem. "(nameoffile.stat.isreg
is undefined and nameoffile.stat.isreg == false)" will never evaluate to
true, as "isreg" cannot be both undefined and false. I think you want to
change the and to an or, as follows (also simplified a little):

when: flag_to_overwrite or nameoffile.stat.isreg is undefined or not
nameoffile.stat.isreg

Hope that helps!


James Cammarata
Director, Ansible Core Engineering
github: jimi-c

On Sat, Apr 4, 2015 at 1:53 AM, Adam R. <[email protected]> wrote:

> Hello,
>
>
> I am using the stat module to check if a file exist, if not, copy from src
> to destination. I also want to setup a flag in order to overwrite
> destination, to achieve this, i am using a conditional like the one on the
> *when* clause:
>
> - stat: path=/path/to/file
>   register: nameoffile
> - copy: src=/home/user/source.tar.gz dest=/destination/path/file owner=root
> group=root
>   when: flag_to_overwrite == true or (nameoffile.stat.isreg is undefined
> and nameoffile.stat.isreg == false)
>
>
> In vars/main.yml:
> flag_to_overwrite: true
>
>
> If the destination does exist and flag_to_overwrite is set to true,  when
> i run the playbook, ansible-playbook doesn't show any error, but the file
> is not overwritten.
>
> If i use only the variable flag_to_overwrite, the value it's been
> evaluated and works ok (true copies the file, false does not do anything).
>   when: flag_to_overwrite == true
>
>
> I have used:
> when: flag_to_overwrite or (nameoffile.stat.isreg is undefined and
> nameoffile.stat.isreg == false)
>
> when: (flag_to_overwrite == true) or (nameoffile.stat.isreg is undefined
> and nameoffile.stat.isreg == false)
>
> but the compound conditional does not work.
>
>
> Any hint?
>
>
> Thanks in advance!
>
>
> Ansible 1.7
>
>
>
>
>
>  --
> 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/74d19de5-32a7-4b40-b31b-3617fe18af5e%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/74d19de5-32a7-4b40-b31b-3617fe18af5e%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/CAMFyvFhxmi3i%3DAGy9QcOSUBf%3D2Rnpw5WvyvzkSdNYNe%3D6uHxzw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to