
    Vh+                        d dl mZ dZdZdZd dlZd dlmZ d dl	m
Z
 d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ 	 d dlZd dlmZ eZ G d de      Zy# e$ r Y w xY w)    )annotationsa
  
name: lookup
author: Felix Fontein (@felixfontein)
short_description: Look up DNS records
version_added: 2.6.0
requirements:
  - dnspython >= 1.15.0 (maybe older versions also work)
  - ipaddress (on Python 2.7 when using O(server))
description:
  - Look up DNS records.
options:
  _terms:
    description:
      - Domain name(s) to query.
    type: list
    elements: str
    required: true
  type:
    description:
      - The record type to retrieve.
    type: str
    default: A
    choices:
      - A
      - AAAA
      - CAA
      - CNAME
      - DNAME
      - DNSKEY
      - DS
      - HINFO
      - LOC
      - MX
      - NAPTR
      - NS
      - NSEC
      - NSEC3
      - NSEC3PARAM
      - PTR
      - RP
      - RRSIG
      - SOA
      - SPF
      - SRV
      - SSHFP
      - TLSA
      - TXT
  query_retry:
    description:
      - Number of retries for DNS query timeouts.
    type: int
    default: 3
  query_timeout:
    description:
      - Timeout per DNS query in seconds.
    type: float
    default: 10
  server:
    description:
      - The DNS server(s) to use to look up the result. Must be a list of one or more IP addresses.
      - By default, the system's standard resolver is used.
    type: list
    elements: str
  servfail_retries:
    description:
      - How often to retry on SERVFAIL errors.
    type: int
    default: 0
  nxdomain_handling:
    description:
      - How to handle NXDOMAIN errors. These appear if an unknown domain name is queried.
      - V(empty) (default) returns an empty result for that domain name. This means that for the corresponding domain name,
        nothing is added to RV(_result).
      - V(fail) makes the lookup fail.
      - V(message) adds the string V(NXDOMAIN) to RV(_result).
    type: str
    choices:
      - empty
      - fail
      - message
    default: empty
  search:
    description:
      - If V(false), the input is assumed to be an absolute domain name.
      - If V(true), the input is assumed to be a relative domain name if it does not end with C(.), the search list configured
        in the system's resolver configuration will be used for relative names, and the resolver's domain may be added to
        relative names.
      - Note that this behavior changed in community.dns 3.0.0. In community.dns 2.x.y, O(search=false) was the only available
        choice.
    type: bool
    default: true
    version_added: 3.0.0
notes:
  - Note that when using this lookup plugin with V(lookup(\)), and the result is a one-element list, Ansible simply returns
    the one element not as a list. Since this behavior is surprising and can cause problems, it is better to use V(query(\))
    instead of V(lookup(\)). See the examples and also R(Forcing lookups to return lists, query) in the Ansible documentation.
a%  
- name: Look up A (IPv4) records for example.org
  ansible.builtin.debug:
    msg: "{{ query('community.dns.lookup', 'example.org.') }}"

- name: Look up AAAA (IPv6) records for example.org
  ansible.builtin.debug:
    msg: "{{ query('community.dns.lookup', 'example.org.', type='AAAA' ) }}"
z
_result:
  description:
    - The records of type O(type) for all queried DNS names.
    - If multiple DNS names are queried in O(_terms), the resulting lists have been concatenated.
  type: list
  elements: str
  sample:
    - 127.0.0.1
N)AnsibleLookupError)to_text)
LookupBase)NAME_TO_RDTYPE)is_ip_address)SimpleResolver)assert_requirements_present)guarded_run)	RdataTypec                  z    e Zd Ze	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 dd       Z	 d	 	 	 	 	 	 	 d	dZy)
LookupModulec                L     d fd}t        |t              S )Nc                     	 j                  dk(        } | sg S | D cg c]  }t        |       c}S c c}w # t        j                  j                  $ r dk(  rdgcY S t        d       w xY w)Nempty)rdtypeserver_addressesnxdomain_is_emptytarget_can_be_relativesearchmessageNXDOMAINzGot NXDOMAIN when querying )resolver   dnsresolverr   r   )	rrsetdatanamenxdomain_handlingr   r   r   r   r   s	     g/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/dns/plugins/lookup/lookup.pycallbackz'LookupModule._resolve.<locals>.callback   s    O ((!%5&77&B+A! )  I278$888<<(( O$	1&<'(+Ftf)MNNOs   ? ? :? ? %A5&A5error_classserver)return	list[str])r   r   )r   r   r   r   r   r   r   r!   s   ``````` r    _resolvezLookupModule._resolve   s'    	O 	O$ *
 	
    c                      fdS )Nc                 &     j                        S N)resolve_addressesr   r$   s   r    <lambda>z,LookupModule._get_resolver.<locals>.<lambda>   s    x11&9 r(    r-   s   ``r    _get_resolverzLookupModule._get_resolver   s     :9r(   Nc                   t        dd       | j                  ||       t        | j                  d      | j                  d      | j                  d            }t        | j                  d         }| j                  d	      }| j                  d
      }d }| j                  d      rtg }t        dd       | j                  d      }	|	D ]P  }
t        |
      r|j                  |
        |j                  t        | j                  ||
      t        |
             R g }|D ]2  }|j                  | j                  |t        |      |||||             4 |S )Nzcommunity.dns.lookuplookup)var_optionsdirectquery_timeoutquery_retryservfail_retries)timeouttimeout_retriesr7   typer   r   r$   r"   )r   r   )%assert_requirements_present_dnspythonset_optionsr	   
get_optionr   %assert_requirements_present_ipaddressr   appendextendr   r0   r   r'   r   )selfterms	variableskwargsr   r   r   r   r   serversr$   resultr   s                r    runzLookupModule.run   sa    	..DhOYv>!OOO4 OOM:!__-?@
   78CG??D
 x0-1??8$!12H(S!%!:G! 
 ($++F3 ''**8V<$6%	
  	DMMDM$%+1!  
	 r(   )TT)r   r	   r   strr   r   r   zlist[str] | Noner   z%t.Literal['empty', 'fail', 'message']r   boolr   rI   r%   r&   )r   r	   r$   rH   r%   zt.Callable[[], list[str]]r+   )rB   zlist[t.Any]rC   zt.Any | NonerD   zt.Anyr%   r&   )__name__
__module____qualname__staticmethodr'   r0   rG   r/   r(   r    r   r      s     (,
 

 
 +	

 A
 !%
 
 

 
B : :*-:	": : =A3 3-93LQ3	3r(   r   ) 
__future__r   DOCUMENTATIONEXAMPLESRETURNtypingtansible.errorsr   +ansible.module_utils.common.text.convertersr   ansible.plugins.lookupr   Hansible_collections.community.dns.plugins.module_utils.dnspython_recordsr   :ansible_collections.community.dns.plugins.module_utils.ipsr   ?ansible_collections.community.dns.plugins.module_utils.resolverr	   :ansible_collections.community.dns.plugins.plugin_utils.ipsr
   r>   ?ansible_collections.community.dns.plugins.plugin_utils.resolverr;   r   dns.resolverr   dns.rdatatyper   intImportErrorr   r/   r(   r    <module>r`      s    #`D	
  - ? - U
'
 I\: \  		s   
A   A('A(