community.general.filetree – recursively match all files in a directory tree

Note

This plugin is part of the community.general collection.

To install it use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.filetree.

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 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
string / required
path(s) of files to read

Examples

- name: Create directories
  ansible.builtin.file:
    path: /web/{{ item.path }}
    state: directory
    mode: '{{ item.mode }}'
  with_community.general.filetree: web/
  when: item.state == 'directory'

- name: Template files (explicitly skip directories in order to use the 'src' attribute)
  ansible.builtin.template:
    src: '{{ item.src }}'
    dest: /web/{{ item.path }}
    mode: '{{ item.mode }}'
  with_community.general.filetree: web/
  when: item.state == 'file'

- name: Recreate symlinks
  ansible.builtin.file:
    src: '{{ item.src }}'
    dest: /web/{{ item.path }}
    state: link
    force: yes
    mode: '{{ item.mode }}'
  with_community.general.filetree: web/
  when: item.state == 'link'

- name: list all files under web/
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.filetree', 'web/') }}"

Authors

There were some errors parsing the documentation for this plugin. Please file a bug with the collection.

The errors were:

  • Unable to normalize filetree: return due to: 9 validation errors for PluginReturnSchema
    return -> _raw -> contains -> group -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)
    return -> _raw -> contains -> owner -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)
    return -> _raw -> contains -> path -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)
    return -> _raw -> contains -> root -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)
    return -> _raw -> contains -> selevel -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)
    return -> _raw -> contains -> serole -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)
    return -> _raw -> contains -> setype -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)
    return -> _raw -> contains -> seuser -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)
    return -> _raw -> contains -> src -> type
      string does not match regex "^(bool|complex|dict|float|int|list|str)$" (type=value_error.str.regex; pattern=^(bool|complex|dict|float|int|list|str)$)