You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/lib/ansible
Dag Wieers 1268f4778d Introduce new 'filetree' lookup plugin (#14332)
* Introduce new 'filetree' lookup plugin

The new "filetree" lookup plugin makes it possible to recurse over a tree of files within the task loop. This makes it possible to e.g. template a complete tree of files to a target system with little effort while retaining permissions and ownership.

The module supports directories, files and symlinks.

The item dictionary consists of:
 - src
 - root
 - path
 - mode
 - state
 - owner
 - group
 - seuser
 - serole
 - setype
 - selevel
 - uid
 - gid
 - size
 - mtime
 - ctime

EXAMPLES:
Here is an example of how we use with_filetree within a role:

```yaml
 - name: Create directories
   file:
     path: /web/{{ item.path }}
     state: directory
     mode: '{{ item.mode }}'
     owner: '{{ item.owner }}'
     group: '{{ item.group }}'
     force: yes
   with_filetree: web/
   when: item.state == 'directory'

 - name: Template complete tree
   file:
     src: '{{ item.src }}'
     dest: /web/{{ item.path }}
     state: 'link'
     mode: '{{ item.mode }}'
     owner: '{{ item.owner }}'
     group: '{{ item.group }}'
   with_filetree: web/
   when: item.state == 'link'

 - name: Template complete tree
   template:
     src: '{{ item.src }}'
     dest: /web/{{ item.path }}
     mode: '{{ item.mode }}'
     owner: '{{ item.owner }}'
     group: '{{ item.group }}'
     force: yes
   with_filetree: web/
   when: item.state == 'file'
```

SPECIAL USE:
The following properties also have its special use:

 - root: Makes it possible to filter by original location
 - path: Is the relative path to root
 - uid, gid: Makes it possible to force-create by exact id, rather than by name
 - size, mtime, ctime: Makes it possible to filter out files by size, mtime or ctime

TODO:
 - Add snippets to documentation

* Small fixes for Python 3

* Return the portion of the file’s mode that can be set by os.chmod()

And remove the exists=True, which is redundant.

* Use lstat() instead of stat() since we support symlinks

* Avoid a few possible stat() calls

* Bring in line with v1.9 and hybrid plugin

* Remove glob module since we no longer use it

* Included suggestions from @RussellLuo

- Two blank lines will be better. See PEP 8
- I think if props is not None is more conventional 😄

* Support failed pwd/grp lookups

* Implement first-found functionality in the path-order
8 years ago
..
cli added check and diff mode control to console 8 years ago
compat Bundle a new version of python-six for compatibility along with some code to make it easy for distributions to override the bunndled copy if they have a new enough version. 9 years ago
config Making the switch to v2 10 years ago
errors Fix some typos (#16498) 9 years ago
executor Cache tasks by uuid in PlayIterator for O(1) lookups 8 years ago
galaxy Fixes #163 in galaxy-issues 8 years ago
inventory Performance improvements 8 years ago
module_utils Fix classes that select a subclass based on platform (#17034) 8 years ago
modules update submodule refs, fixes build in ansible-modules-extras 8 years ago
parsing warn when searching for an empty string or null 8 years ago
playbook Several fixes for includes 8 years ago
plugins Introduce new 'filetree' lookup plugin (#14332) 8 years ago
template allow spaces before the filter string (#16312) 9 years ago
utils Add missing version_added (#17050) 8 years ago
vars Move tasks/blocks to a single parent model 8 years ago
__init__.py Fix ziploader for the cornercase of ansible invoking ansible. 9 years ago
constants.py * Fix race in creating temp directories pre-fork (#16965) 8 years ago
release.py Fix ziploader for the cornercase of ansible invoking ansible. 9 years ago
test-requirements.txt Making the switch to v2 10 years ago