
    VhX                    Z    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  G d d	e      Zy
)    )annotationsam  
    name: vars
    author: Ansible Core Team
    version_added: "2.5"
    short_description: Lookup templated value of variables
    description:
      - 'Retrieves the value of an Ansible variable. Note: Only returns top level variable names.'
    options:
      _terms:
        description: The variable names to look up.
        required: True
      default:
        description:
            - What to return if a variable is undefined.
            - If no default is set, it will result in an error if any of the variables is undefined.
    seealso:
    - plugin_type: lookup
      plugin: ansible.builtin.varnames

aZ  
- name: Show value of 'variablename'
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'variabl' + myvar) }}"
  vars:
    variablename: hello
    myvar: ename

- name: Show default empty since i dont have 'variablnotename'
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'variabl' + myvar, default='') }}"
  vars:
    variablename: hello
    myvar: notename

- name: Produce an error since i dont have 'variablnotename'
  ansible.builtin.debug: msg="{{ q('vars', 'variabl' + myvar) }}"
  ignore_errors: True
  vars:
    variablename: hello
    myvar: notename

- name: find several related variables
  ansible.builtin.debug: msg="{{ query('ansible.builtin.vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}"

- name: show values from variables found via varnames (note "*" is used to dereference the list to a 'list of arguments')
  debug: msg="{{ q('vars', *q('varnames', 'ansible_play_.+')) }}"

- name: Access nested variables
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'variabl' + myvar).sub_var }}"
  ignore_errors: True
  vars:
    variablename:
        sub_var: 12
    myvar: ename

- name: alternate way to find some 'prefixed vars' in loop
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'ansible_play_' + item) }}"
  loop:
    - hosts
    - batch
    - hosts_all
z]
_value:
  description:
    - value of the variables requested.
  type: list
  elements: raw
)AnsibleErrorAnsibleUndefinedVariable)string_types)
LookupBasec                      e Zd ZddZy)LookupModuleNc           	     *   ||| j                   _        t        | j                   di       }| j                  ||       | j	                  d      }g }|D ]_  }t        |t              st        d|dt        |            	 	 ||   }|j                  | j                   j                  |d	
             a |S # t        $ r. 	 |d   |d      |   }n# t        $ r t        d|z        w xY wY fw xY w# t        $ r ||j                  |       n Y w xY w)N_available_variables)var_optionsdirectdefaultzInvalid setting identifier, "z" is not a string, its a hostvarsinventory_hostnamez$No variable found with this name: %sT)fail_on_undefined)_templaravailable_variablesgetattrset_options
get_option
isinstancer   r   typeKeyErrorr   appendtemplate)	selfterms	variableskwargsmyvarsr   rettermvalues	            K/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/lookup/vars.pyrunzLookupModule.runS   sA    09DMM-(>CYv>//), 	DdL1"cgimnris#tuuf"4LE 

4==11%41PQ	( 
   ff &z 26:N3O PQU V# f67]`d7deef f , &JJw' (sH   B7,C17	C.CC.C((C.+C1-C..C11DD)N)__name__
__module____qualname__r%        r$   r	   r	   Q   s    r*   r	   N)
__future__r   DOCUMENTATIONEXAMPLESRETURNansible.errorsr   r   ansible.module_utils.sixr   ansible.plugins.lookupr   r	   r)   r*   r$   <module>r2      s8    #*(T
 B 1 -: r*   