o nnh @sXddlmZdZdZdZddlZddlZddlmZddl m Z m Z Gdd d eZ dS) ) annotationsa name: fileglob author: Michael DeHaan version_added: "1.4" short_description: list files matching a pattern description: - Matches all files in a single directory, non-recursively, that match a pattern. It calls Python's "glob" library. options: _terms: description: path(s) of files to read required: True notes: - Patterns are only supported on files, not directory/paths. - See R(Ansible task paths,playbook_task_paths) to understand how file lookup occurs with paths. - Matching is against local system files on the Ansible controller. To iterate a list of files on a remote node, use the M(ansible.builtin.find) module. - Returns a string list of paths joined by commas, or an empty list if no files match. For a 'true list' pass O(ignore:wantlist=True) to the lookup. seealso: - ref: playbook_task_paths description: Search paths used for relative files. a_ - name: Display paths of all .txt files in dir ansible.builtin.debug: msg={{ lookup('ansible.builtin.fileglob', '/my/path/*.txt') }} - 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/*" zS _list: description: - list of files type: list elements: path N) LookupBase)to_bytesto_textc@seZdZdddZdS) LookupModuleNc Ksg}|D]e}tj|}g}||kr!|||dtj|n#d|vr*|d}n||g}|D]} |tj| d|| q2|D]"} | rhtt tj| |dd} dd| D} | rh| | nqFq|S)Nfilesansible_search_pathsurrogate_or_stricterrorscSs$g|]}tj|rt|ddqS)r r )ospathisfiler).0grJ/usr/local/lib/python3.10/dist-packages/ansible/plugins/lookup/fileglob.py Qs$z$LookupModule.run..) r r basenameappendfind_file_in_search_pathdirname get_basedirjoinglobrextend) selfterms variableskwargsretterm term_file found_pathspathsp dwimmed_pathglobbed term_resultsrrrrun<s*     zLookupModule.run)N)__name__ __module__ __qualname__r)rrrrr:sr) __future__r DOCUMENTATIONEXAMPLESRETURNr ransible.plugins.lookupr+ansible.module_utils.common.text.convertersrrrrrrrs