Parameter |
Choices/Defaults |
Configuration |
Comments |
---|---|---|---|
_terms
required |
|
|
list of file names
|
paths
|
|
|
list of paths in which to look for the files
|
- name: show first existing file
debug: msg={{lookup('first_found', findme)}}
vars:
findme:
- "/path/to/foo.txt"
- "bar.txt" # will be looked in files/ dir relative to role and/or play
- "/path/to/biz.txt"
- name: |
copy first existing file found to /some/file,
looking in relative directories from where the task is defined and
including any play objects that contain it
copy: src={{lookup('first_found', findme)}} dest=/some/file
vars:
findme:
- foo
- "{{inventory_hostname}}"
- bar
- name: same copy but specific paths
copy: src={{lookup('first_found', findme, mypaths}} dest=/some/file
vars:
findme:
- foo
- "{{inventory_hostname}}"
- bar
mypaths:
- /tmp/production
- /tmp/staging
- name: INTERFACES | Create Ansible header for /etc/network/interfaces
template:
src: "{{ lookup('first_found', findme)}}"
dest: "/etc/foo.conf"
vars:
findme:
- "{{ ansible_virtualization_type }}_foo.conf"
- "default_foo.conf"
- name: read vars from first file found, use 'vars/' relative subdir
include_vars: "{{lookup('first_found', findme, paths=['vars'])}}"
vars:
findme:
- '{{ansible_os_distribution}}.yml'
- '{{ansible_os_family}}.yml'
- default.yml
Common return values are documented here, the following are the fields unique to this lookup:
Key |
Returned |
Description |
---|---|---|
_raw
|
path to file found
|
Hint
If you notice any issues in this documentation you can edit this document to improve it.