community.general/lib/ansible/plugins/lookup
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
2016-08-11 23:33:54 -04:00
..
__init__.py fixed lookup search path (#16630) 2016-07-13 10:06:34 -04:00
cartesian.py fix cartesian lookup 2016-02-11 10:35:37 -05:00
consul_kv.py no need to be executable 2015-11-16 14:40:35 -08:00
credstash.py Make credstash lookup plugin support encryption contexts 2016-01-02 15:23:27 +07:00
csvfile.py fixed lookup search path (#16630) 2016-07-13 10:06:34 -04:00
dict.py Support any Mapping for with_dict lookup. 2015-08-17 20:11:24 -04:00
dig.py Cleanup more pyflakes warnings (2 real problems) 2015-10-19 12:01:01 -07:00
dnstxt.py Cleanup more pyflakes warnings (2 real problems) 2015-10-19 12:01:01 -07:00
env.py listify lookup plugin terms when they're specified as "{{ lookup(terms) }}" 2015-08-10 09:07:37 -07:00
etcd.py Support etcd v2. Use this version by default (#12312) 2016-06-06 11:26:12 -04:00
file.py fixed lookup search path (#16630) 2016-07-13 10:06:34 -04:00
fileglob.py Restore previous behavior of ignoring missing files via with_fileglob (#17053) 2016-08-11 19:55:21 -04:00
filetree.py Introduce new 'filetree' lookup plugin (#14332) 2016-08-11 23:33:54 -04:00
first_found.py fixed lookup search path (#16630) 2016-07-13 10:06:34 -04:00
flattened.py Cleaning up FIXMEs 2015-10-22 16:03:50 -04:00
hashi_vault.py raise AnsibleError in hashi_vault lookup plugin when hvac module is not installed (#16859) 2016-08-04 10:06:12 -07:00
indexed_items.py Cleaning up FIXMEs 2015-10-22 16:03:50 -04:00
ini.py fixed lookup search path (#16630) 2016-07-13 10:06:34 -04:00
inventory_hostnames.py corrected host/group match in inventory_hostnames 2016-01-20 18:32:39 -05:00
items.py listify lookup plugin terms when they're specified as "{{ lookup(terms) }}" 2015-08-10 09:07:37 -07:00
lines.py Cleanup more pyflakes warnings (2 real problems) 2015-10-19 12:01:01 -07:00
list.py Add python3-compat boilerplate to all .py files in lib/ansible 2015-10-19 18:36:19 -07:00
nested.py Remove mysterious old cruft 2015-10-01 20:32:08 +05:30
password.py Lookup password omit salt (#16361) 2016-06-27 10:44:25 -07:00
pipe.py listify lookup plugin terms when they're specified as "{{ lookup(terms) }}" 2015-08-10 09:07:37 -07:00
random_choice.py Making the switch to v2 2015-05-03 21:47:26 -05:00
redis_kv.py listify lookup plugin terms when they're specified as "{{ lookup(terms) }}" 2015-08-10 09:07:37 -07:00
sequence.py Cleanup some pyflakes warning (1 real error) 2015-10-19 11:42:46 -07:00
shelvefile.py fixed lookup search path (#16630) 2016-07-13 10:06:34 -04:00
subelements.py Cleanup some pyflakes warning (1 real error) 2015-10-19 11:42:46 -07:00
template.py fixed lookup search path (#16630) 2016-07-13 10:06:34 -04:00
together.py Cleanup some pyflakes warning (1 real error) 2015-10-19 11:42:46 -07:00
url.py Finish up plugin porting to global display 2015-11-11 10:44:23 -08:00