a ì)gÓ ã@spddlmZmZmZeZdZdZdZddl Z ddl Z ddl m Z ddl mZddlmZmZGd d „d e ƒZdS) é)Úabsolute_importÚdivisionÚprint_functionad 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 C(wantlist=True) to the lookup. 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)ÚAnsibleFileNotFound)Úto_bytesÚto_textc@seZdZddd„ZdS)Ú LookupModuleNc KsØg}|D]Ê}tj |¡}g}||krB| | |dtj |¡¡¡nFd|vrT|d}n | |¡g}|D]"} | tj | d¡¡| | ¡qd|D]D} | rŒt t tj | |¡dd¡} dd„| Dƒ} | rŒ|  | ¡qqŒq|S)NÚfilesZansible_search_pathÚsurrogate_or_strict©ÚerrorscSs$g|]}tj |¡rt|dd‘qS)r r )ÚosÚpathÚisfiler)Ú.0Úg©rúC/usr/lib/python3.9/site-packages/ansible/plugins/lookup/fileglob.pyÚ Póz$LookupModule.run..) rrÚbasenameÚappendZfind_file_in_search_pathÚdirnameZ get_basedirÚjoinÚglobrÚextend) ÚselfZtermsZ variablesÚkwargsÚretZtermZ term_fileZ found_pathsÚpathsÚpZ dwimmed_pathZglobbedZ term_resultsrrrÚrun;s(     zLookupModule.run)N)Ú__name__Ú __module__Ú __qualname__r"rrrrr 9sr )Z __future__rrrÚtypeZ __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNrrZansible.plugins.lookuprZansible.errorsrZansible.module_utils._textrrr rrrrÚs