관리-도구
편집 파일: vars.cpython-39.pyc
a �)g� � @ s` d dl mZmZmZ eZdZdZdZd dl m Z mZ d dlm Z d dlmZ G dd � d e�Zd S )� )�absolute_import�division�print_functiona 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. a� - 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="{{ lookup('ansible.builtin.vars', 'variabl' + myvar)}}" ignore_errors: True vars: variablename: hello myvar: notename - name: find several related variables ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}" - 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 @ s e Zd Zddd�ZdS )�LookupModuleNc K s |d ur|| j _t| j di �}| j||d� | �d�}g }|D ]�}t|t�s`td|t|�f ��zrz|| }W nJ t y� z|d |d | }W n t y� t d| ��Y n0 Y n0 |�| j j|dd �� W q> t y� |d ur�|�|� n� Y q>0 q>|S ) NZ_available_variables)Zvar_optionsZdirect�defaultz:Invalid setting identifier, "%s" is not a string, its a %sZhostvarsZinventory_hostnamez$No variable found with this name: %sT)Zfail_on_undefined) Z_templarZavailable_variables�getattrZset_optionsZ get_option� isinstancer r �type�KeyErrorr �append�template) �selfZtermsZ variables�kwargsZmyvarsr �retZterm�value� r �?/usr/lib/python3.9/site-packages/ansible/plugins/lookup/vars.py�runM s. zLookupModule.run)N)�__name__� __module__�__qualname__r r r r r r K s r N)Z __future__r r r r Z __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNZansible.errorsr r Zansible.module_utils.sixr Zansible.plugins.lookupr r r r r r �<module> s '