
    Vho%                        d dl mZ dZdZdZd dlmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZmZ d d	lmZ d d
lmZ  e       Z G d de      Zy)    )annotationsa  
name: url
author: Brian Coca (@bcoca)
version_added: "1.9"
short_description: return contents from URL
description:
    - Returns the content of the URL requested to be used as data in play.
options:
  _terms:
    description: urls to query
  validate_certs:
    description: Flag to control SSL certificate validation
    type: boolean
    default: True
  split_lines:
    description: Flag to control if content is returned as a list of lines or as a single text blob
    type: boolean
    default: True
  use_proxy:
    description: Flag to control if the lookup will observe HTTP proxy environment variables when present.
    type: boolean
    default: True
  username:
    description: Username to use for HTTP authentication.
    type: string
    version_added: "2.8"
  password:
    description: Password to use for HTTP authentication.
    type: string
    version_added: "2.8"
  headers:
    description: HTTP request headers
    type: dictionary
    default: {}
    version_added: "2.9"
  force:
    description: Whether or not to set "cache-control" header with value "no-cache"
    type: boolean
    version_added: "2.10"
    default: False
    vars:
        - name: ansible_lookup_url_force
    env:
        - name: ANSIBLE_LOOKUP_URL_FORCE
    ini:
        - section: url_lookup
          key: force
  timeout:
    description: How long to wait for the server to send data before giving up
    type: float
    version_added: "2.10"
    default: 10
    vars:
        - name: ansible_lookup_url_timeout
    env:
        - name: ANSIBLE_LOOKUP_URL_TIMEOUT
    ini:
        - section: url_lookup
          key: timeout
  http_agent:
    description: User-Agent to use in the request. The default was changed in 2.11 to V(ansible-httpget).
    type: string
    version_added: "2.10"
    default: ansible-httpget
    vars:
        - name: ansible_lookup_url_agent
    env:
        - name: ANSIBLE_LOOKUP_URL_AGENT
    ini:
        - section: url_lookup
          key: agent
  force_basic_auth:
    description: Force basic authentication
    type: boolean
    version_added: "2.10"
    default: False
    vars:
        - name: ansible_lookup_url_force_basic_auth
    env:
        - name: ANSIBLE_LOOKUP_URL_FORCE_BASIC_AUTH
    ini:
        - section: url_lookup
          key: force_basic_auth
  follow_redirects:
    description: String of urllib2, all/yes, safe, none to determine how redirects are followed
    type: string
    version_added: "2.10"
    default: 'urllib2'
    vars:
        - name: ansible_lookup_url_follow_redirects
    env:
        - name: ANSIBLE_LOOKUP_URL_FOLLOW_REDIRECTS
    ini:
        - section: url_lookup
          key: follow_redirects
    choices:
      all: Will follow all redirects.
      none: Will not follow any redirects.
      safe: Only redirects doing GET or HEAD requests will be followed.
      urllib2: Defer to urllib2 behavior (As of writing this follows HTTP redirects).
      'no': (DEPRECATED, removed in 2.22) alias of V(none).
      'yes': (DEPRECATED, removed in 2.22) alias of V(all).
  use_gssapi:
    description:
    - Use GSSAPI handler of requests
    - As of Ansible 2.11, GSSAPI credentials can be specified with O(username) and O(password).
    type: boolean
    version_added: "2.10"
    default: False
    vars:
        - name: ansible_lookup_url_use_gssapi
    env:
        - name: ANSIBLE_LOOKUP_URL_USE_GSSAPI
    ini:
        - section: url_lookup
          key: use_gssapi
  use_netrc:
    description:
    - Determining whether to use credentials from ``~/.netrc`` file
    - By default .netrc is used with Basic authentication headers
    - When set to False, .netrc credentials are ignored
    type: boolean
    version_added: "2.14"
    default: True
    vars:
        - name: ansible_lookup_url_use_netrc
    env:
        - name: ANSIBLE_LOOKUP_URL_USE_NETRC
    ini:
        - section: url_lookup
          key: use_netrc
  unix_socket:
    description: String of file system path to unix socket file to use when establishing connection to the provided url
    type: string
    version_added: "2.10"
    vars:
        - name: ansible_lookup_url_unix_socket
    env:
        - name: ANSIBLE_LOOKUP_URL_UNIX_SOCKET
    ini:
        - section: url_lookup
          key: unix_socket
  ca_path:
    description: String of file system path to CA cert bundle to use
    type: string
    version_added: "2.10"
    vars:
        - name: ansible_lookup_url_ca_path
    env:
        - name: ANSIBLE_LOOKUP_URL_CA_PATH
    ini:
        - section: url_lookup
          key: ca_path
  unredirected_headers:
    description: A list of headers to not attach on a redirected request
    type: list
    elements: string
    version_added: "2.10"
    vars:
        - name: ansible_lookup_url_unredir_headers
    env:
        - name: ANSIBLE_LOOKUP_URL_UNREDIR_HEADERS
    ini:
        - section: url_lookup
          key: unredirected_headers
  ciphers:
    description:
      - SSL/TLS Ciphers to use for the request
      - 'When a list is provided, all ciphers are joined in order with C(:)'
      - See the L(OpenSSL Cipher List Format,https://www.openssl.org/docs/manmaster/man1/openssl-ciphers.html#CIPHER-LIST-FORMAT)
        for more details.
      - The available ciphers is dependent on the Python and OpenSSL/LibreSSL versions
    type: list
    elements: string
    version_added: '2.14'
    vars:
        - name: ansible_lookup_url_ciphers
    env:
        - name: ANSIBLE_LOOKUP_URL_CIPHERS
    ini:
        - section: url_lookup
          key: ciphers
a  
- name: url lookup splits lines by default
  ansible.builtin.debug: msg="{{item}}"
  loop: "{{ lookup('ansible.builtin.url', 'https://github.com/gremlin.keys', wantlist=True) }}"

- name: display ip ranges
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.url', 'https://ip-ranges.amazonaws.com/ip-ranges.json', split_lines=False) }}"

- name: url lookup using authentication
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2') }}"

- name: url lookup using basic authentication
  ansible.builtin.debug:
    msg: "{{ lookup('ansible.builtin.url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2', force_basic_auth='True') }}"

- name: url lookup using headers
  ansible.builtin.debug:
    msg: "{{ lookup('ansible.builtin.url', 'https://some.private.site.com/api/service', headers={'header1':'value1', 'header2':'value2'} ) }}"
zg
  _list:
    description: list of list of lines or content of url(s)
    type: list
    elements: str
)	HTTPErrorURLError)AnsibleError)to_text	to_native)open_urlConnectionErrorSSLValidationError)
LookupBase)Displayc                      e Zd ZddZy)LookupModuleNc           
     F   | j                  ||       g }|D ]  }t        j                  d|z         | j                  d      dv rt        j	                  dd       	 t        |fi d| j                  d      d	| j                  d	      d
| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      d| j                  d      }| j                  d      r?|j                         j                         D ]  }|j                  t        |              |j                  t        |j                                       |S # t        $ r}t        d|dt        |            d }~wt        $ r}t        d|dt        |            d }~wt        $ r}t        d|dt        |            d }~wt        $ r}t        d|dt        |            d }~ww xY w) N)var_optionsdirectzurl lookup connecting to %sfollow_redirects)yesnozCUsing 'yes' or 'no' for 'follow_redirects' parameter is deprecated.z2.22)versionvalidate_certs	use_proxyurl_usernameusernameurl_passwordpasswordheadersforcetimeout
http_agentforce_basic_auth
use_gssapiunix_socketca_pathunredirected_headersciphers	use_netrczReceived HTTP error for z : zFailed lookup url for z.Error validating the server's certificate for z: zError connecting to split_lines)set_optionsdisplayvvvv
get_option
deprecatedr	   r   r   r   r   r   r
   read
splitlinesappendr   )	selfterms	variableskwargsrettermresponseelines	            J/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/lookup/url.pyrunzLookupModule.run   s   Yv> '	5DLL6=>12mC""Y" # X#)-9I)J"ook: "&!< "&!<	
 !OOI6 //'2 !OOI6  $|< &*__5G%H &*__5G%H  $|< !% > !OOI6 *.9O)P !OOI6  #ook:!6 }-$MMO668 .DJJwt}-. 

78==?34O'	5P 
  ]"iXYl#[\\ ["dIVWL#YZZ% r"]aclmnco#pqq" X"4ST#VWWXs=   D*H	J H))J 5IJ I55J JJ )N)__name__
__module____qualname__r;        r:   r   r      s    -r@   r   N)
__future__r   DOCUMENTATIONEXAMPLESRETURNurllib.errorr   r   ansible.errorsr   +ansible.module_utils.common.text.convertersr   r   ansible.module_utils.urlsr	   r
   r   ansible.plugins.lookupr   ansible.utils.displayr   r*   r   r?   r@   r:   <module>rK      sK    #vp(
 - ' J S S - )
)/: /r@   