
    Vh                    x    d dl mZ dZdZdZd dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ  e       Z G d	 d
e
      Zy)    )annotationsa  
    name: file
    author: Daniel Hokka Zakrisson (!UNKNOWN) <daniel@hozac.com>
    version_added: "0.9"
    short_description: read file contents
    description:
        - This lookup returns the contents from a file on the Ansible controller's file system.
    options:
      _terms:
        description: path(s) of files to read
        required: True
      rstrip:
        description: whether or not to remove whitespace from the ending of the looked-up file
        type: bool
        required: False
        default: True
      lstrip:
        description: whether or not to remove whitespace from the beginning of the looked-up file
        type: bool
        required: False
        default: False
    notes:
      - if read in variable context, the file can be interpreted as YAML if the content is valid to the parser.
      - this lookup does not understand 'globbing', use the fileglob lookup instead.
    seealso:
      - ref: playbook_task_paths
        description: Search paths used for relative files.
aG  
- ansible.builtin.debug:
    msg: "the value of foo.txt is {{ lookup('ansible.builtin.file', '/etc/foo.txt') }}"

- name: display multiple file contents
  ansible.builtin.debug: var=item
  with_file:
    - "/path/to/foo.txt"
    - "bar.txt"  # will be looked in files/ dir relative to play or in role
    - "/path/to/biz.txt"
zV
  _raw:
    description:
      - content of file(s)
    type: list
    elements: str
)AnsibleErrorAnsibleOptionsErrorAnsibleLookupError)
LookupBase)to_text)Displayc                      e Zd ZddZy)LookupModuleNc                $   g }| j                  ||       |D ]  }t        j                  d|z         	 | j                  |d|d      }t        j	                  d|z         |r| j
                  j                  |      \  }}t        |d      }	| j                  d	      r|	j                         }	| j                  d
      r|	j                         }	|j                  |	       nt        d       |S # t        $ r}
t        d|z  |
      d }
~
ww xY w)N)var_optionsdirectzFile lookup term: %sfilesT)ignore_missingzFile lookup using %s as filesurrogate_or_strict)errorslstriprstripz0file not found, use -vvvvv to see paths searchedz6The 'file' lookup had an issue accessing the file '%s')orig_exc)set_optionsdisplaydebugfind_file_in_search_pathvvvv_loader_get_file_contentsr   
get_optionr   r   appendr   r   r   )selfterms	variableskwargsretterm
lookupfile
b_contents	show_datacontentses              K/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/lookup/file.pyrunzLookupModule.runA   s   Yv> 	vDMM0478v!::9gtdh:i
<zIJ,0LL,K,KJ,W)J	&z:OPHx0#+??#4x0#+??#4JJx( ..`aa )	v( 
   v()adh)hstuuvs   B9C11	D:D

D)N)__name__
__module____qualname__r+        r*   r   r   ?   s    r0   r   N)
__future__r   DOCUMENTATIONEXAMPLESRETURNansible.errorsr   r   r   ansible.plugins.lookupr   +ansible.module_utils.common.text.convertersr   ansible.utils.displayr	   r   r   r/   r0   r*   <module>r9      sD    #:

 Q P - ? )
): r0   