
    Vh                    ^    d dl mZ dZdZdZd dlZd dlZd dlmZ d dl	m
Z
mZ  G d d	e      Zy)
    )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_bytesto_textc                      e Zd ZddZy)LookupModuleNc           
        g }|D ]d  }t         j                  j                  |      }g }||k7  r@|j                  | j	                  |dt         j                  j                  |                   ncd|v r|d   }n| j                  |      g}|D ]B  }	|j                  t         j                  j                  |	d             |j                  |	       D |D ]  }
|
st        j                  t        t         j                  j                  |
|      d            }|D cg c]/  }t         j                  j                  |      s#t        |d      1 }}|s|j                  |        d g |S c c}w )Nfilesansible_search_pathsurrogate_or_strict)errors)ospathbasenameappendfind_file_in_search_pathdirnameget_basedirjoinglobr   isfiler   extend)selfterms	variableskwargsretterm	term_filefound_pathspathspdwimmed_pathglobbedgterm_resultss                 O/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/lookup/fileglob.pyrunzLookupModule.run<   sR    	D((.IKD ""4#@#@GUWU\U\UdUdeiUj#kl )I5%&;<E!--i89E *A&&rww||Aw'?@&&q)* !, "iilI1V_t(uvGV]#sQRacahahaoaopqarGA6K$L#sL#s#

<0	, 
	 $ts   $E/E/)N)__name__
__module____qualname__r(        r'   r   r   :   s    r-   r   )
__future__r   DOCUMENTATIONEXAMPLESRETURNr   r   ansible.plugins.lookupr   +ansible.module_utils.common.text.convertersr   r   r   r,   r-   r'   <module>r4      s9    #.
 
  - I: r-   