ansible.builtin.filetree (v2.9.27) — lookup

recursively match all files in a directory tree

| "added in version" 2.4 of ansible.builtin"

Authors: Dag Wieers (@dagwieers) <dag@wieers.com>

Install Ansible via pip

Install with pip install ansible==2.9.27

Description

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.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create directories
  file:
    path: /web/{{ item.path }}
    state: directory
    mode: '{{ item.mode }}'
  with_filetree: web/
  when: item.state == 'directory'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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'

Inputs

    
_terms:
    description: path(s) of files to read
    required: true

Outputs

_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