On this page
filetree - recursively match all files in a directory tree
New in version 2.4.
Synopsis
- This lookup enables you to template a complete tree of files on a target system while retaining permissions and ownership.
- Supports directories, files and symlinks, including SELinux and other file properties
- If you provide more than one path, it will implement a with_first_found logic, and will not process entries it already processed in previous paths. This enables merging different trees in order of importance, or add role_vars to specific paths to influence different instances of the same role.
Parameters
Parameter | Choices/Defaults | Configuration | Comments |
---|---|---|---|
_terms
required
|
path(s) of files to read
|
Examples
- name: Create directories
file:
path: /web/{{ item.path }}
state: directory
mode: '{{ item.mode }}'
with_filetree: web/
when: item.state == 'directory'
- name: Template files
template:
src: '{{ item.src }}'
dest: /web/{{ item.path }}
mode: '{{ item.mode }}'
with_filetree: web/
when: item.state == 'file'
- name: Recreate symlinks
file:
src: '{{ item.src }}'
dest: /web/{{ item.path }}
state: link
force: yes
mode: '{{ item.mode }}'
with_filetree: web/
when: item.state == 'link'
Return Values
Common return values are documented here, the following are the fields unique to this lookup:
Key | Returned | Description | |
---|---|---|---|
_raw |
list of dictionaries with file information
|
||
src |
TODO
|
||
root |
allows filtering by original location
|
||
path |
contains the relative path to root
|
||
mode |
TODO
|
||
state |
TODO
|
||
owner |
TODO
|
||
group |
TODO
|
||
seuser |
TODO
|
||
serole |
TODO
|
||
setype |
TODO
|
||
selevel |
TODO
|
||
uid |
TODO
|
||
gid |
TODO
|
||
size |
TODO
|
||
mtime |
TODO
|
||
ctime |
TODO
|
Status
Author
- Dag Wieers (@dagwieers) <dag@wieers.com>
Hint
If you notice any issues in this documentation you can edit this document to improve it.
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.6/plugins/lookup/filetree.html