checking if particular file exists locally before go

268 views
Skip to first unread message

Nick Evgeniev

unread,
Jun 30, 2014, 5:50:09 PM6/30/14
to ansible...@googlegroups.com
hi,

given ansible role directory layout:
files
vars
tasks
...

and having files/foo/hostname/somefile I want not only be able  to copy this file like:
- copy src=foo/{{ ansible_hostname }}/somefile dest=...

but also to limit certain steps depending whether such file exist or not... basically to define variable and condition other steps on it. unfortunately stat module is limited to remote host.. what's the other way around?


Michael DeHaan

unread,
Jun 30, 2014, 6:03:38 PM6/30/14
to ansible...@googlegroups.com
"I want not only be able  to copy this file"

copy module, but you've got that

"but also to limit certain steps depending whether such file exist or not."

when statement

"basically to define variable and condition other steps on it."

include_vars + when statement

"unfortunately stat module is limited to remote host.."

local_action






--
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/abc04355-05c1-4acb-bc96-511dc2e247db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick Evgeniev

unread,
Jun 30, 2014, 6:18:42 PM6/30/14
to ansible...@googlegroups.com
the idea was to define variable automatically based on whether file exist or not. as a temporary solution i had to declare variable in host_vars. and yes i'm using when statement :)

it looks like 'stat' module doesn't understand the 'magic' of role directory  layout, so I would have to specify full path.. am I missing something?

Michael DeHaan

unread,
Jun 30, 2014, 7:10:06 PM6/30/14
to ansible...@googlegroups.com
"it looks like 'stat' module doesn't understand the 'magic' of role directory  layout, so I would have to specify full path.. am I missing something?"

{{ playbook_dir}}/roles/foo/files/bar.txt



Reply all
Reply to author
Forward
0 new messages