ansible / ansible.builtin / v2.9.27 / lookup / filetree recursively match all files in a directory tree | "added in version" 2.4 of ansible.builtin" Authors: Dag Wieers (@dagwieers) <dag@wieers.com>ansible.builtin.filetree (v2.9.27) — lookup
pip
Install with pip install ansible==2.9.27
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 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.
- name: Create directories file: path: /web/{{ item.path }} state: directory mode: '{{ item.mode }}' with_filetree: web/ when: item.state == 'directory'
- name: Template files (explicitly skip directories in order to use the 'src' attribute) 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'
_terms: description: path(s) of files to read required: true
_raw: contains: ctime: description: TODO gid: description: TODO group: description: TODO mode: description: TODO mtime: description: TODO owner: description: TODO path: description: contains the relative path to root root: description: allows filtering by original location selevel: description: TODO serole: description: TODO setype: description: TODO seuser: description: TODO size: description: TODO src: description: - full path to file - not returned when C(item.state) is set to C(directory) state: description: TODO uid: description: TODO description: list of dictionaries with file information