
    Vh                     r    d Z ddlmZmZmZ eZdZdZdZ	ddl
mZ ddlmZ ddlmZ dd	lmZ  G d
 de      Zy)z
The to_paths lookup plugin
    )absolute_importdivisionprint_functionau  
    name: to_paths
    author: Bradley Thornton (@cidrblock)
    version_added: "1.0.0"
    short_description: Flatten a complex object into a dictionary of paths and values
    description:
      - Flatten a complex object into a dictionary of paths and values.
      - Paths are dot delimited whenever possible.
      - Brackets are used for list indices and keys that contain special characters.
      - B(to_paths) is also available as a filter plugin.
      - Using the parameters below- C(lookup('ansible.utils.to_paths', var, prepend, wantlist))
    options:
      var:
        description:
          - The value of I(var) will be used.
        type: raw
        required: True
      prepend:
        description:
          - Prepend each path entry. Useful to add the initial I(var) name.
        type: str
        required: False
      wantlist:
        description:
          - If set to I(True), the return value will always be a list.
          - This can also be accomplished using C(query) or B(q) instead of C(lookup).
          - U(https://docs.ansible.com/ansible/latest/plugins/lookup.html)
        type: bool

    notes:
aK  

#### Simple examples

- ansible.builtin.set_fact:
    a:
      b:
        c:
          d:
            - 0
            - 1
          e:
            - true
            - false

- ansible.builtin.set_fact:
    paths: "{{ lookup('ansible.utils.to_paths', a) }}"

# TASK [ansible.builtin.set_fact] ********************************************
# ok: [nxos101] => changed=false
#   ansible_facts:
#     paths:
#       b.c.d[0]: 0
#       b.c.d[1]: 1
#       b.c.e[0]: True
#       b.c.e[1]: False

- name: Use prepend to add the initial variable name
  ansible.builtin.set_fact:
    paths: "{{ lookup('ansible.utils.to_paths', a, prepend='a') }}"

# TASK [Use prepend to add the initial variable name] **************************
# ok: [nxos101] => changed=false
#   ansible_facts:
#     paths:
#       a.b.c.d[0]: 0
#       a.b.c.d[1]: 1
#       a.b.c.e[0]: True
#       a.b.c.e[1]: False


#### Using a complex object

- name: Make an API call
  ansible.builtin.uri:
    url: "https://nxos101/restconf/data/openconfig-interfaces:interfaces"
    headers:
      accept: "application/yang.data+json"
    url_password: password
    url_username: admin
    validate_certs: false
  register: result
  delegate_to: localhost

- name: Flatten the complex object
  ansible.builtin.set_fact:
    paths: "{{ lookup('ansible.utils.to_paths', result.json) }}"

# TASK [Flatten the complex object] ******************************************
# ok: [nxos101] => changed=false
#   ansible_facts:
#     paths:
#       interfaces.interface[0].config.enabled: 'true'
#       interfaces.interface[0].config.mtu: '1500'
#       interfaces.interface[0].config.name: eth1/71
#       interfaces.interface[0].config.type: ethernetCsmacd
#       interfaces.interface[0].ethernet.config['auto-negotiate']: 'true'
#       interfaces.interface[0].ethernet.state.counters['in-crc-errors']: '0'
#       interfaces.interface[0].ethernet.state.counters['in-fragment-frames']: '0'
#       interfaces.interface[0].ethernet.state.counters['in-jabber-frames']: '0'
#       interfaces.interface[0].ethernet.state.counters['in-mac-control-frames']: '0'
#       <...>
z
  _raw:
    description:
      - A dictionary of key value pairs.
      - The key is the path.
      - The value is the value.
)AnsibleLookupError)
LookupBase)AnsibleArgSpecValidator)to_pathsc                       e Zd Zd Zy)LookupModulec                     t        |t              rddg}t        t        ||            }|j	                  |       t        |t        d      }|j                         \  }}}|st        |      d|d<   t        di |}	|	S )Nvarprependr	   )dataschemanameTwantlist )

isinstancelistdictzipupdater   DOCUMENTATIONvalidater   r	   )
selfterms	variableskwargskeysaavvaliderrorsupdated_dataress
             i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/ansible/utils/plugins/lookup/to_paths.pyrunzLookupModule.run   s}    eT"9%DT5)*EV%5ZX&)lln#v|$V,,#'Z &&
    N)__name__
__module____qualname__r&   r   r'   r%   r   r      s    r'   r   N)__doc__
__future__r   r   r   type__metaclass__r   EXAMPLESRETURNansible.errorsr   ansible.plugins.lookupr   Nansible_collections.ansible.utils.plugins.module_utils.common.argspec_validater   Fansible_collections.ansible.utils.plugins.module_utils.common.to_pathsr	   r   r   r'   r%   <module>r5      sQ    A @ @HT
 . - \: r'   