checking if particular file exists locally before go

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?

“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

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 :slight_smile:

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?

“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