%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/plugins/inventory/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/plugins/inventory/__pycache__/__init__.cpython-39.pyc

a

�)g�P�@s:ddlmZmZmZeZddlZddlZddlZddl	m
Z
ddlmZm
Z
ddlmZddlmZddlmZddlmZdd	lmZmZdd
lmZddlmZddlm Z dd
l!m"Z"ddl#m$Z$m%Z%e"�Z&dd�Zddd�Z'd dd�Z(dd�Z)Gdd�de�Z*Gdd�de*�Z+Gdd�de,�Z-Gdd�de,�Z.dS)!�)�absolute_import�division�print_functionN)�Mapping)�AnsibleError�AnsibleParserError)�to_safe_group_name)�
parse_address)�
AnsiblePlugin)�CachePluginAdjudicator)�to_bytes�	to_native)�boolean)�string_types)�Templar)�Display)�combine_vars�load_extra_varscCst|ddd�S)NT)�forceZsilent)�
original_safe)�name�r�F/usr/lib/python3.9/site-packages/ansible/plugins/inventory/__init__.pyr,srcCsd|vS)z�
    A helper function that checks a given host line to see if it contains
    a range pattern described in the docstring above.

    Returns True if the given line contains a pattern, else False.
    �[r)�linerrr�detect_range1srcs�g}|�r�|�ddd��ddd��d�\}}}|�d�}t|�dkrXt|�dkrXtd��|d	}|d}t|�dkrzd}n|d}|s�d
}|s�td��|d	d
kr�t|�dkr�t|���t|�kr�td���fd
d�}	nt}	zJtj�|�}
tj�|�}|
|k�rtd��ttj|
|dt	|���}Wn0t
�yVtt	|�t	|�dt	|��}Yn0|D]>}
d�||	|
�|f�}t
|��r�|�t|��n
|�|��q\|SdS)a�
    A helper function that expands a given line that contains a pattern
    specified in top docstring, and returns a list that consists of the
    expanded version.

    The '[' and ']' characters are used to maintain the pseudo-code
    appearance. They are replaced in this function with '|' to ease
    string splitting.

    References: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#hosts-and-groups
    r�|��]�:��z.host range must be begin:end or begin:end:stepr�0z!host range must specify end valuez:host range must specify equal-length begin and end formatscst|����S�N)�str�zfill)�x�Zrlenrr�fillisz#expand_hostname_range.<locals>.fillz!host range must have begin <= end�N)�replace�split�lenrr$�string�
ascii_letters�index�list�int�
ValueError�range�joinr�extend�expand_hostname_range�append)rZ	all_hosts�headZnrange�tailZboundsZbeg�end�stepr(Zi_begZi_end�seqZrseqZhnamerr'rr6;sF$

 "
r6c
Ks�zt|fi|��}WnBtyV}z*dt|�vr>td|��n|�WYd}~n
d}~00|dkr�|r�t|jdd�s�td�|���|S)NZfact_caching_connectionaerror, '%s' inventory cache plugin requires the one of the following to be set to a writeable directory path:
ansible.cfg:
[default]: fact_caching_connection,
[inventory]: cache_connection;
Environment:
ANSIBLE_INVENTORY_CACHE_CONNECTION,
ANSIBLE_CACHE_PLUGIN_CONNECTION.Zmemory�_optionsz�Unable to use cache plugin {0} for inventory. Cache options were provided but may not reconcile correctly unless set via set_options. Refer to the porting guide if the plugin derives user settings from ansible.constants.)�CacheObjectrr
�getattrZ_plugin�format)�plugin_name�kwargs�cache�errr�get_cache_plugin�s��rEcs`eZdZdZdZee�Z�fdd�Zddd�Z	dd	�Z
ddd�Zd
d�Zdd�Z
dd�Z�ZS)�BaseInventoryPluginz Parses an Inventory Source�	generatorcs*tt|���i|_d|_t|_i|_dSr#)�superrF�__init__r=�	inventory�display�_vars��self��	__class__rrrI�s
zBaseInventoryPlugin.__init__TcCs&||_||_t|d�|_t|�|_dS)az Populates inventory from the given data. Raises an error on any parse failure
            :arg inventory: a copy of the previously accumulated inventory data,
                 to be updated with any new data this plugin provides.
                 The inventory can be empty if no other source/plugin ran successfully.
            :arg loader: a reference to the DataLoader, which can read in YAML and JSON files,
                 it also has Vault support to automatically decrypt files.
            :arg path: the string that represents the 'inventory source',
                 normally a path to a configuration file for this inventory,
                 but it can also be a raw string for this plugin to consume
            :arg cache: a boolean that indicates if the plugin should use the cache or not
                 you can ignore if this plugin does not implement caching.
        )�loaderN)rQrJr�templarrrL)rNrJrQ�pathrCrrr�parse�szBaseInventoryPlugin.parsecCs@d}t|dd�}tj�|�r0t�|tj�r0d}n|j�d�|S)a� Verify if file is usable by this plugin, base does minimal accessibility check
            :arg path: a string that was passed as an inventory source,
                 it normally is a path to a config file, but this is not a requirement,
                 it can also be parsed itself as the inventory data to process.
                 So only call this base class if you expect it to be a file.
        F�surrogate_or_strict��errorsTzWSkipping due to inventory source not existing or not being readable by the current user)r�osrS�exists�access�R_OKrKZvvv)rNrSZvalid�b_pathrrr�verify_file�szBaseInventoryPlugin.verify_fileNcCsXt|t�stdt|���|D]4}|jj|||d�|D]}|j�||||�q8qdS)Nz8Invalid data from file, expected dictionary and got:

%s)�group�port)�
isinstancerrr
rJ�add_host�set_variable)rN�hosts�	variablesr^r_�host�krrr�_populate_host_vars�s
z'BaseInventoryPlugin._populate_host_varsc
si}z�jj|dd�}Wn0tyH}ztt|���WYd}~n
d}~00t�d�pZ�jg}|srtdt|���n>|�d�|vr�td|�dd���nt|t	�s�td	t
|����j|�jd
�d�j
v�r��d��rgd�}t�fd
d�|D��}t��d�fi|���_|S)z� validate config and set options as appropriate
            :arg path: path to common yaml format config file for this plugin
        F)rCNZ_redirected_namesz%s is emptyZpluginz!Incorrect plugin name in file: %sz
none foundzJinventory source has invalid structure, it should be a dictionary, got: %s)ZdirectZvar_optionsrC�)Z_uriZcache_connection)�_timeoutZ
cache_timeout)�_prefixZcache_prefixc3s6|].}��|d�dur|d��|d�fVqdS�rNr��
get_option��.0�optrMrr�	<genexpr>��z8BaseInventoryPlugin._read_config_data.<locals>.<genexpr>�cache_plugin)rQZload_from_file�	Exceptionrr
r?�NAME�getr`r�typeZset_optionsrLr=rm�dictrE�_cache)rNrSZconfigrDZvalid_names�cache_option_keys�
cache_optionsrrMr�_read_config_data�s$"
z%BaseInventoryPlugin._read_config_datacCs(|jD]}||vr|�|�|j|<qdS)a< update existing options from alternate configuration sources not normally used by Ansible.
            Many API libraries already have existing configuration sources, this allows plugin author to leverage them.
            :arg data: key/value pairs that correspond to configuration options for this plugin
        N)r=�pop)rN�datarfrrr�_consume_options�s
z$BaseInventoryPlugin._consume_optionscCsPzt|dd�\}}Wnty.|}d}Yn0t|�rBt|�}n|g}||fS)z�
        Takes a single host pattern and returns a list of hostnames and an
        optional port number that applies to all of them.
        T)Zallow_rangesN)r	rtrr6)rNZhostpattern�patternr_Z	hostnamesrrr�_expand_hostpatterns

z'BaseInventoryPlugin._expand_hostpattern)T)NN)�__name__�
__module__�__qualname__�__doc__�TYPE�staticmethodr�_sanitize_group_namerIrTr]rgr|rr��
__classcell__rrrOrrF�s	

	"
rFcs$eZdZdZdZ�fdd�Z�ZS)�BaseFileInventoryPluginz% Parses a File based Inventory SourceZstoragecstt|���dSr#)rHr�rIrMrOrrrI!sz BaseFileInventoryPlugin.__init__)r�r�r�r�r�rIr�rrrOrr�sr�c@sNeZdZe�Zedd��Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�ZdS)�	CacheablecCs|jSr#)ryrMrrrrC*szCacheable.cachecs>��d�}gd�}t�fdd�|D��}t|fi|���_dS)Nrsrhc3s6|].}��|d�dur|d��|d�fVqdSrkrlrnrMrrrq1rrz.Cacheable.load_cache_plugin.<locals>.<genexpr>)rmrxrEry)rNrArzr{rrMr�load_cache_plugin.s
zCacheable.load_cache_plugincCsd�|j|�|��S)Nz{0}_{1})r@ru�_get_cache_prefix)rNrSrrr�
get_cache_key4szCacheable.get_cache_keycCsdt��}|�t|jdd��|��}t��}|�t|dd��|��}d�|dd�|dd�g�S)z7 create predictable unique prefix for plugin/inventory rUrVZs_N�)�hashlibZsha1�updaterruZ	hexdigestr4)rNrS�mZd1�nZd2rrrr�7szCacheable._get_cache_prefixcCs|j��dSr#)ry�flushrMrrr�clear_cacheDszCacheable.clear_cachecCs|j��dSr#)ry�update_cache_if_changedrMrrrr�Gsz!Cacheable.update_cache_if_changedcCs|j��dSr#)ryZ	set_cacherMrrr�set_cache_pluginJszCacheable.set_cache_pluginN)
r�r�r�r>ry�propertyrCr�r�r�r�r�r�rrrrr�&s

r�c@s4eZdZddd�Zd
dd�Zddd�Zdd	d
�ZdS)�
ConstructableTcCsf|j}z|�d�}Wnty*d}Yn0|r@t||j�|_n||_|jd|jj||jj	f|d�S)zi helper method for plugins to compose variables for Ansible based on jinja2 expression and inventory varsZuse_extra_varsF�%s%s%s)�disable_lookups)
rRrmrtrrL�available_variables�templateZenvironmentZvariable_start_stringZvariable_end_string)rNr�rdr��tZ	use_extrarrr�_composePs
�zConstructable._composeFcCs�|r�t|t�r�|D]t}z|�|||�}WnJtyt}z2|rTtd||t|�f��WYd}~qWYd}~n
d}~00|j�|||�qdS)z5 loops over compose entries to create vars for hosts z Could not set %s for host %s: %sN)r`rxr�rtrr
rJrb)rNZcomposerdre�strictZvarnameZ	compositerDrrr�_set_composite_varsas"z!Constructable._set_composite_varsc
Cs�|r�t|t�r�|r(t||j�|����}||j_|D]�}d||}|�|�}zt	|j�
|��}WnJty�}	z2|r�td||t
|	�f��WYd}	~	q4WYd}	~	n
d}	~	00|r4|j�|�}|j�||�q4dS)z} helper to create complex groups for plugins based on jinja2 conditionals, hosts that meet the conditional are added to groupz3{%% if %s %%} True {%% else %%} False {%% endif %%}z%Could not add host %s to group %s: %sN)r`rxrrJ�get_host�get_varsrRr�r�rr�rtrr
�	add_group�	add_child)
rN�groupsrdrer��fetch_hostvarsZ
group_nameZconditional�resultrDrrr�_add_host_to_composed_groupsms 
"z*Constructable._add_host_to_composed_groupscCs>|�r:t|t��r:|D�] }|�r,t|t��r,|rHt||j�|����}z|�|�d�|�}WnPt	y�}z8|r�t
d||�d�t|�f��WYd}~qWYd}~n
d}~00|�dd�}	|�d�}
|
dur�|	dur�t
d��|s�|dk�r|	du�r|�dd�}|�d	d
�}|�dd�}
|
�r�z|j�
|
�}
WnNt�y~}z4|�r^t
d|
|t|�f��WYd}~qWYd}~n
d}~00g}t|t��r�|dk�r�|	du�r�|�|	�n
|�|�n�t|t��r|D]0}|dk�r�|	du�r�|�|	�n
|�|��q�n|t|t��rl|��D]T\}}d
|||f}|dk�r\|	du�rNd
|||	f}n|
du�r\|}|�|��qnt
dt|���|D]|}|dk�r�|�d�du�r�d}|�d
|||f�}|j�|�}|j�||�|
�r�|�|
�}|j�|�|j�||��q�n*|�r8|gifv�r8t
d|�d�|f��qt
d|��qdS)zc helper to create groups for plugins based on variable values and add the corresponding hosts to it�keyz6Could not generate group for host %s from %s entry: %sNZ
default_value�trailing_separatorzTparameters are mutually exclusive for keyed groups: default_value|trailing_separatorr)�prefix�	separator�_Zparent_groupz3Could not generate parent group %s for group %s: %sr�FzUInvalid group name format, expected a string or a list of them or dictionary, got: %sZleading_separatorz=No key or key resulted empty for %s in host %s, invalid entryz7Invalid keyed group entry, it must be a dictionary: %s )r`r0rxrrJr�r�r�rvrtrr
rRr�rrr7r�itemsrwrmr�r�rar�)rN�keysrdrer�r�Zkeyedr�rDZdefault_value_namer�r��sepZraw_parent_nameZnew_raw_group_namesr�gnameZgvalZ	bare_nameZresult_gname�parent_namerrr�_add_host_to_keyed_groups�sv
"
"



z'Constructable._add_host_to_keyed_groupsN)T)F)FT)FT)r�r�r�r�r�r�r�rrrrr�Ns


r�)N)N)/Z
__future__rrrrwZ
__metaclass__r�rXr-�collections.abcrZansible.errorsrrZansible.inventory.grouprrZansible.parsing.utils.addressesr	Zansible.pluginsr
Zansible.plugins.cacherr>Zansible.module_utils._textrr
Z)ansible.module_utils.parsing.convert_boolrZansible.module_utils.sixrZansible.templaterZansible.utils.displayrZansible.utils.varsrrrKrr6rErFr��objectr�r�rrrr�<module>s4


H
(

Zerion Mini Shell 1.0