Update : stat upside down

83 views
Skip to first unread message

Diogene Laerce

unread,
Jul 24, 2014, 10:12:32 AM7/24/14
to ansible...@googlegroups.com
Hi,

I have this strange issue. The following code was working fine (I think)
as :

############################

- name: Verify Python-3.4.1.tgz download
stat: path=/tmp/Python-3.4.1.tgz
register: a
- name: Extract archive
unarchive: >
src=/tmp/Python-3.4.1.tgz
dest=/home/{{ user_installer }}/src
copy=no
when: a.stat.isfile is not defined

############################

Until today I enable it again in the playbook and it now works "upside
down" :
It does extract the archive only when a.stat.isfile is not defined and
when "a.stat.isfile is defined and a.stat.isfile == true" : it just
skips the whole code.

I rewrite this as it seems that the "isdir" directive works just as it
should. So I guess the issue comes from the "isfile" statement and my
new question : is there a list of all arguments taken by the stat module
? I couldn't find one.

Thank you

--
“One original thought is worth a thousand mindless quotings.”
“Le vrai n'est pas plus sûr que le probable.”

Diogene Laerce





signature.asc

Michael DeHaan

unread,
Jul 24, 2014, 6:44:12 PM7/24/14
to ansible...@googlegroups.com
I think I replied to the previous copy of this one, please see the other thread.

It can sometimes be confusing as the very first post to the list is moderated to prevent spam, so I occasionally double approve a duplicate post.


Diogene Laerce

unread,
Jul 27, 2014, 7:47:31 AM7/27/14
to ansible...@googlegroups.com


On 07/25/2014 12:44 AM, Michael DeHaan wrote:
> I think I replied to the previous copy of this one, please see the other
> thread.

Sorry about that.


> However, I think you might really want this:
> when: a is defined and a.stat.isfile
> OR (depending on use case)
> when: a is defined and not a.stat.isfile
>
> Maybe try one of those first...

I played with that code where /usr/local/bin/python3.4 does not exist :

#####################################

- name: Verify if Python 3.4 is installed
stat: path=/usr/local/bin/python3.4
register: l

- debug: msg=execute
when: l is defined

#####################################

And :

l is defined : trigger the debug message
l is not defined : skipping

l is defined and l.stat.isfile : skipping
l is defined and not l.stat.isfile : skipping

l is not defined and l.stat.isfile : skipping
l is not defined and not l.stat.isfile : skipping

This is executed on localhost, with root privileges.

I actually find that weird as if it functions like stat on linux,
IMU l shouldn't be defined at all, no ?

Thanks.
signature.asc

Michael DeHaan

unread,
Jul 27, 2014, 9:20:27 AM7/27/14
to ansible...@googlegroups.com
I think you are misunderstanding the return codes of the stat module.

When the file is not there, it doesn't register a "None" in the file location.

Insert this line, and you'll see what I mean:

- debug: var=I

I would also recommend naming variables something other than "I", for readability purposes.   python34 would be a good variable name :)




Diogene Laerce

unread,
Jul 27, 2014, 9:56:49 AM7/27/14
to ansible...@googlegroups.com


On 07/27/2014 03:20 PM, Michael DeHaan wrote:
> I think you are misunderstanding the return codes of the stat module.

Nooo.. Why would you say that ? :)


> When the file is not there, it doesn't register a "None" in the file
> location.
>
> Insert this line, and you'll see what I mean:
>
> - debug: var=I

That, is the killer tip ! I was blind, now I see. :D
Problem solved !


> I would also recommend naming variables something other than "I", for
> readability purposes. python34 would be a good variable name :)

I will. ;)

Thanks very thanks a lot for teaching me how to fish ! :)






> On Sun, Jul 27, 2014 at 7:46 AM, 'Diogene Laerce' via Ansible Project
> <ansible...@googlegroups.com
> --
> 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
> <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwJ%3Dji9aDQm5CcuB4cMTVnoKm40Obh7eJ8FKjkDgArPcQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwJ%3Dji9aDQm5CcuB4cMTVnoKm40Obh7eJ8FKjkDgArPcQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
signature.asc
Reply all
Reply to author
Forward
0 new messages