ansible "when:" directive: check file exists, and other nifty things?

157 views
Skip to first unread message

Eric Feliksik

unread,
Feb 2, 2015, 2:09:37 PM2/2/15
to ansible...@googlegroups.com
I can run a task conditionally, depending on the existence of a file, as follows:

- name: check if the file exists
  stat: path=/my/file
  register: file_register
- name: do the actual task
  include: my_subtask.yml
  when: not file_register.stat.exists

Is it not possible to do smarter things in the when clause? Possible with a Jinja2 directive? I tried to search for the documentation of the lookup() function I see sometimes, but cannot find it. Is is part of Ansible or of Jinja? Is it usable here?

Thanks in advance,
Eric

Brian Coca

unread,
Feb 2, 2015, 3:05:23 PM2/2/15
to ansible...@googlegroups.com
lookups are part of ansible, lookups run only on the 'master' so for
this to work all actions would be local.




--
Brian Coca
Reply all
Reply to author
Forward
0 new messages