ansible.builtin.fileglob (v2.16.5) — lookup

list files matching a pattern

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

Authors: Michael DeHaan

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

Matches all files in a single directory, non-recursively, that match a pattern. It calls Python's "glob" library.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Display paths of all .txt files in dir
  ansible.builtin.debug: msg={{ lookup('ansible.builtin.fileglob', '/my/path/*.txt') }}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Copy each file over that matches the given pattern
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: "/etc/fooapp/"
    owner: "root"
    mode: 0600
  with_fileglob:
    - "/playbooks/files/fooapp/*"

Inputs

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

Outputs

_list:
  description:
  - list of files
  elements: path
  type: list

See also