Yohohohohohooho | Sanrei Aya
Sanrei Aya


Server : LiteSpeed
System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : elvh3918 ( 1528)
PHP Version : 8.2.31
Disable Function : mail
Directory :  /usr/lib/python3.9/site-packages/ansible/plugins/inventory/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/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$�stringZ
ascii_letters�index�list�int�
ValueError�range�joinr�extend�expand_hostname_range�append)rZ	all_hosts�headZnrange�tailZboundsZbeg�end�stepr(Zi_begZi_end�seqZrseqZhnamerr'rr5;sF$

 "
r5c
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��rDcs`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#)�superrE�__init__r<�	inventory�display�_vars��self��	__class__rrrH�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)rPrIr�templarrrK)rMrIrP�pathrBrrr�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�osrR�exists�access�R_OKrJZvvv)rMrRZvalid�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
rI�add_host�set_variable)rM�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)rBNZ_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_optionsrB�)Z_uriZcache_connection)�_timeoutZ
cache_timeout)�_prefixZcache_prefixc3s6|].}��|d�dur|d��|d�fVqdS�rNr��
get_option��.0�optrLrr�	<genexpr>��z8BaseInventoryPlugin._read_config_data.<locals>.<genexpr>�cache_plugin)rPZload_from_file�	Exceptionrr
r>�NAME�getr_r�typeZset_optionsrKr<rl�dictrD�_cache)rMrRZconfigrCZvalid_names�cache_option_keys�
cache_optionsrrLr�_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)rM�datarerrr�_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	rsrr5)rMZhostpattern�patternr^Z	hostnamesrrr�_expand_hostpatterns

z'BaseInventoryPlugin._expand_hostpattern)T)NN)�__name__�
__module__�__qualname__�__doc__�TYPE�staticmethodr�_sanitize_group_namerHrSr\rfr{r~r��
__classcell__rrrNrrE�s	

	"
rEcs$eZdZdZdZ�fdd�Z�ZS)�BaseFileInventoryPluginz% Parses a File based Inventory SourceZstoragecstt|���dSr#)rGr�rHrLrNrrrH!sz BaseFileInventoryPlugin.__init__)r�r�r�r�r�rHr�rrrNrr�sr�c@sNeZdZe�Zedd��Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�ZdS)�	CacheablecCs|jSr#)rxrLrrrrB*szCacheable.cachecs>��d�}gd�}t�fdd�|D��}t|fi|���_dS)Nrrrgc3s6|].}��|d�dur|d��|d�fVqdSrjrkrmrLrrrp1rqz.Cacheable.load_cache_plugin.<locals>.<genexpr>)rlrwrDrx)rMr@ryrzrrLr�load_cache_plugin.s
zCacheable.load_cache_plugincCsd�|j|�|��S)Nz{0}_{1})r?rt�_get_cache_prefix)rMrRrrr�
get_cache_key4szCacheable.get_cache_keycCsdt��}|�t|jdd��|��}t��}|�t|dd��|��}d�|dd�|dd�g�S)z7 create predictable unique prefix for plugin/inventory rTrUZs_N�)�hashlibZsha1�updaterrtZ	hexdigestr3)rMrR�mZd1�nZd2rrrr�7szCacheable._get_cache_prefixcCs|j��dSr#)rx�flushrLrrr�clear_cacheDszCacheable.clear_cachecCs|j��dSr#)rx�update_cache_if_changedrLrrrr�Gsz!Cacheable.update_cache_if_changedcCs|j��dSr#)rxZ	set_cacherLrrr�set_cache_pluginJszCacheable.set_cache_pluginN)
r�r�r�r=rx�propertyrBr�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)
rQrlrsrrK�available_variables�templateZenvironmentZvariable_start_stringZvariable_end_string)rMr�rcr��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_rwr�rsrr
rIra)rMZcomposercrd�strictZvarnameZ	compositerCrrr�_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_rwrrI�get_host�get_varsrQr�r�rr�rsrr
�	add_group�	add_child)
rM�groupsrcrdr��fetch_hostvarsZ
group_nameZconditional�resultrCrrr�_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_r/rwrrIr�r�r�rursrr
rQr�rrr6r�itemsrvrlr�r�r`r�)rM�keysrcrdr�r�Zkeyedr�rCZdefault_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__rrrrvZ
__metaclass__r�rWr-�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.varsrrrJrr5rDrEr��objectr�r�rrrr�<module>s4


H
(

Yohohohohohooho | Sanrei Aya