HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible/inventory/__pycache__/manager.cpython-39.pyc
a

�)g2s�@stddlmZmZmZeZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZmZmZddlmZddlmZdd	lmZmZdd
lmZddl m!Z!ddl"m#Z#dd
l$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+e'�Z,gd�Z-dd�ej.D�Z/dd�ej0D�Z1e	�2d�3e-e/e1��Z4e	�2de	j5�Z6dd�Z7dd�Z8Gdd�de9�Z:dS)�)�absolute_import�division�print_functionN)�
attrgetter)�shuffle)�	constants)�AnsibleError�AnsibleOptionsError�AnsibleParserError)�
InventoryData)�string_types)�to_bytes�to_text)�
parse_address)�inventory_loader)�deduplicate_list)�unfrackpath)�Display)�combine_vars)�get_vars_from_inventory_sources)s^\.s^host_vars$s^group_vars$s^vars_plugins$cCsg|]}t|��qS�)r
��.0�xrr�=/usr/lib/python3.9/site-packages/ansible/inventory/manager.py�
<listcomp>0�rcCsg|]}dtt�|���qS)s%s$)r
�re�escaperrrrr1r�|a>^
        (.+)                    # A pattern expression ending with...
        \[(?:                   # A [subscript] expression comprising:
            (-?[0-9]+)|         # A single positive or negative number
            ([0-9]+)([:-])      # Or an x:y or x: range.
            ([0-9]*)
        )\]
        $
    cCspg}g}g}|D]D}|sq|ddkr2|�|�q|ddkrJ|�|�q|�|�q|gkrddg}|||S)zS takes a list of patterns and reorders them by modifier to apply them consistently r�!�&�all)�append)�patternsZpattern_regularZpattern_intersectionZpattern_exclude�prrr�order_patternsBsr&cCs�t|t�r(dd�|D�}ttj�|��St|t�s>t|dd�}d|vrR|�d�}nBzt|dd�\}}|g}Wn&t	y�t
�td�|t
j�}Yn0d	d
�|D�S)a�
    Takes a string containing host patterns separated by commas (or a list
    thereof) and returns a list of single patterns (which may not contain
    commas). Whitespace is ignored.

    Also accepts ':' as a separator for backwards compatibility, but it is
    not recommended due to the conflict with IPv6 addresses and host ranges.

    Example: 'a,b[1], c[2:3] , d' -> ['a', 'b[1]', 'c[2:3]', 'd']
    css|]}t|�VqdS�N)�split_host_pattern�rr%rrr�	<genexpr>krz%split_host_pattern.<locals>.<genexpr>�surrogate_or_strict��errors�,T)Zallow_rangesaJ(?:     # We want to match something comprising:
                        [^\s:\[\]]  # (anything other than whitespace or ':[]'
                        |           # ...or...
                        \[[^\]]*\]  # a single complete bracketed expression)
                    )+              # occurring once or more
                cSsg|]}|��r|���qSr)�stripr)rrrr�rz&split_host_pattern.<locals>.<listcomp>)
�
isinstance�list�	itertools�chain�
from_iterablerr�splitr�	Exceptionr�findall�X)�pattern�resultsr$�base�portrrrr(^s 


�
	r(c@seZdZdZd@dd�Zedd��Zedd	��Zed
d��ZdAdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdBdd�ZdCdd�Zdd�Zdd �Zd!d"�ZdDd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�ZdEd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!dS)F�InventoryManagerz Creates and manages inventory NTcCsp||_t�|_d|_d|_i|_i|_|dur6g|_nt|t	�rJ|g|_n||_|r`|j
|d�g|_g|_dS)N��cache)
�_loaderr�
_inventory�_restriction�_subset�_hosts_patterns_cache�_pattern_cache�_sourcesr0r�
parse_sources�_cached_dynamic_hosts�_cached_dynamic_grouping)�self�loaderZsources�parser?rrr�__init__�s

zInventoryManager.__init__cCs|j�d�S)N�	localhost�rA�get_host�rJrrrrN�szInventoryManager.localhostcCs|jjSr')rA�groupsrQrrrrR�szInventoryManager.groupscCs|jjSr')rA�hostsrQrrrrS�szInventoryManager.hostscCs|j�|||�Sr')rA�add_host)rJ�host�groupr<rrrrT�szInventoryManager.add_hostcCs|j�|�Sr')rA�	add_group)rJrVrrrrW�szInventoryManager.add_groupcCs
|j��Sr')rA�get_groups_dictrQrrrrX�sz InventoryManager.get_groups_dictcCs|��|j��Sr')�clear_cachesrA�reconcile_inventoryrQrrrrZ�sz$InventoryManager.reconcile_inventorycCs|j�|�Sr'rO)rJ�hostnamerrrrP�szInventoryManager.get_hostcCsRt�d�g}tjD],}t�|�}|r2|�|�qt�d|�q|sNtd��|S)z, sets up loaded inventory plugins for usage zsetting up inventory pluginsz,Failed to load inventory plugin, skipping %sz^No inventory plugins available to generate inventory, make sure you have at least one enabled.)	�displayZvvvv�CZINVENTORY_ENABLEDr�getr#�warningr)rJZplugins�name�pluginrrr�_fetch_inventory_plugins�s


z)InventoryManager._fetch_inventory_pluginsFcCs�d}|jD]6}|r
d|vr&t|dd�}|j||d�}|r
|s
d}q
|rR|j��n tjrbtd��ntjrrt	�
d�|j��D]"}t
|jt|j|j|gd��|_q||j��D]"}t
|jt|j|j|gd��|_q�d	S)
zA iterate over inventory sources and parse each one to populate itFr.)�followr>TzENo inventory was parsed, please check your configuration and options.z=No inventory was parsed, only implicit localhost is available�	inventoryN)rFr�parse_sourcerArZr]ZINVENTORY_UNPARSED_IS_FAILEDrZINVENTORY_UNPARSED_WARNINGr\r_rR�valuesr�varsrr@rS)rJr?�parsed�sourcerLrVrUrrrrG�s$


 zInventoryManager.parse_sourcescCsd}g}t�d|�t|�}tj�|�r�t�d|�tt�|��D]\}t�d|�t�	|�rdqFt
tj�||�dd�}|j||d�}t�d||f�|sF|}qF�n�||j
_|��D�]�}	t
t|	d	t|	d
d���}
t�d|
|	jf�zt|	�|��}Wnt�yd}Yn0|�rDzZ|	j|j
|j||d�z|	��Wnt�yTYn0d
}t�d||
f�W�qXWn�t�y�}zJt�d||
f�d�t�t��d��}
|�||
||
d��WYd}~npd}~0t�y@}zNt�d|
|f�d�t�t��d��}
|�||
t |�|
d��WYd}~n
d}~00q�t�d|
|f�q�|�rr|j
j!�|j
j�n�|dk�s�tj�"|��r|�r�|D]J}t�#dt
|d�|dt
|d�f�d|v�r�t�t
|d���q�t$j%�r�t d|��nt�#d|�d|j
_|S)z6 Generate or update inventory for the source provided Fz'Examining possible inventory source: %sz.Searching for inventory files in directory: %szConsidering %sr+r,r>zparsed %s as %sZ
_load_name�_original_path�z Attempting to use plugin %s (%s)Tz)Parsed %s inventory source with %s pluginz%s was not parsable by %s�)�srcra�exc�tbNz&%s failed while attempting to parse %szB%s declined parsing %s as it did not pass its verify_file() methodz/etc/ansible/hostsz(
* Failed to parse %s with %s plugin: %srmrarnroz.Completely failed to parse inventory source %sz)Unable to parse %s as an inventory source)&r\�debugr
�os�path�isdir�sorted�listdir�IGNORED�searchr�joinrerAZcurrent_sourcerb�getattrrj�boolZverify_filer6rLr@Zupdate_cache_if_changed�AttributeErrorZvvvr
�	traceback�	format_tb�sys�exc_infor#rZprocessed_sources�existsr_r]Z INVENTORY_ANY_UNPARSED_IS_FAILED)rJrir?rhZfailuresZb_source�i�fullpathZparsed_this_oneraZplugin_nameZplugin_wants�eroZfailrrrre�sn


(0(
zInventoryManager.parse_sourcecCsi|_i|_dS)z clear all caches N)rDrErQrrrrYRszInventoryManager.clear_cachescCs`|��t�|_|jdd�|jD]}|�|ddi�q"|jD]\}}d|d<|�||�q>dS)z recalculate inventory Fr>�refreshTN)rYrrArGrH�add_dynamic_hostrI�add_dynamic_group)rJrU�resultrrr�refresh_inventoryWs
z"InventoryManager.refresh_inventorycCszz4|ddks t�t�|��}nt�|dd��}WntyRtd|��Yn0g}|D]}|�|�r\|�|�q\|S)Nr�~�zInvalid host list pattern: %s)r�compile�fnmatch�	translater6r�matchr#)rJ�itemsZpattern_strr9r:�itemrrr�_match_listcs
zInventoryManager._match_listr"c	shg}t|t�r|dd�}n|g}|�rd|s>�jr>|��j�|sT�jrT|��j�t|�}|�jvr�t|�}��|�}|s��jr�t	dd����j�D����fdd�|D�}|sʈjrʇfdd�|D�}t
|��j|<|dv�rt�j|dd�td�|d	kd
�}n\|dk�r(�j|ddd�}n<�j|dd�}|d
k�rNt
|�n|dv�rdtd|��|S)z�
        Takes a pattern or list of patterns and returns a list of matching
        inventory host names, taking into account any active restrictions
        or applied subsets
        Ncss|]}|jVqdSr'�Z_uuid)r�srrrr*�rz-InventoryManager.get_hosts.<locals>.<genexpr>csg|]}|j�vr|�qSrr��r�h)�subset_uuidsrrr�rz.InventoryManager.get_hosts.<locals>.<listcomp>csg|]}|j�jvr|�qSr)r`rBr�rQrrr�r)rt�reverse_sortedr`r�)�key�reverseZreverse_inventory���r)Nrdz1Invalid 'order' specified for inventory hosts: %s)r0r1rC�extendrB�tuplerDr(�_evaluate_patterns�setrrtrrr	)	rJr9Z
ignore_limitsZignore_restrictions�orderrSZpattern_listZpattern_hashr$r)rJr�r�	get_hoststs:







&



zInventoryManager.get_hostscs�t|�}g}|D]�}||jjvr4|�|j�|��q|�|��|ddkrft����fdd�|D�}q|ddkr�t����fdd�|D�}qtdd�|D���|��fd	d��D��q|S)
z�
        Takes a list of patterns and returns a list of matching host names,
        taking into account any negative and intersection patterns.
        rr csg|]}|�vr|�qSrrr���thatrrr�rz7InventoryManager._evaluate_patterns.<locals>.<listcomp>r!csg|]}|�vr|�qSrrr�r�rrr�rcss|]}|jVqdSr'�r`)r�yrrrr*�rz6InventoryManager._evaluate_patterns.<locals>.<genexpr>csg|]}|j�vr|�qSrr�r�)�existing_hostsrrr�r)r&rArSr#rP�_match_one_patternr�r�)rJr$rSr%r)r�r�rr��s
z#InventoryManager._evaluate_patternscCs~|ddvr|dd�}||jvrt|�|�\}}|�|�}z|�||�}Wntyhtd|��Yn0||j|<|j|S)a�
        Takes a single pattern and returns a list of matching host names.
        Ignores intersection (&) and exclusion (!) specifiers.

        The pattern may be:

            1. A regex starting with ~, e.g. '~[abc]*'
            2. A shell glob pattern with ?/*/[chars]/[!chars], e.g. 'foo*'
            3. An ordinary word that matches itself only, e.g. 'foo'

        The pattern is matched using the following rules:

            1. If it's 'all', it matches all hosts in all groups.
            2. Otherwise, for each known group name:
                (a) if it matches the group name, the results include all hosts
                    in the group or any of its children.
                (b) otherwise, if it matches any hosts in the group, the results
                    include the matching hosts.

        This means that 'foo*' may match one or more groups (thus including all
        hosts therein) but also hosts in other groups.

        The built-in groups 'all' and 'ungrouped' are special. No pattern can
        match these group names (though 'all' behaves as though it matches, as
        described above). The word 'ungrouped' can match a host of that name,
        and patterns like 'ungr*' and 'al*' can match either hosts or groups
        other than all and ungrouped.

        If the pattern matches one or more group names according to these rules,
        it may have an optional range suffix to select a subset of the results.
        This is allowed only if the pattern is not a regex, i.e. '~foo[1]' does
        not work (the [1] is interpreted as part of the regex), but 'foo*[1]'
        would work if 'foo*' matched the name of one or more groups.

        Duplicate matches are always eliminated from the results.
        r)r!r r�Nz-No hosts matched the subscripted pattern '%s')rE�_split_subscript�_enumerate_matches�_apply_subscript�
IndexErrorr)rJr9�expr�slicerSrrrr��s&


z#InventoryManager._match_one_patterncCs||ddkr|dfSd}t�|�}|rt|��\}}}}}|rJt|�df}n*|sRd}t|�t|�f}|dkrtt�d�||fS)aa
        Takes a pattern, checks if it has a subscript, and returns the pattern
        without the subscript and a (start,end) tuple representing the given
        subscript (or None if there is no subscript).

        Validates that the subscript is in the right syntax, but doesn't make
        sure the actual indices make sense in context.
        rr�Nr��-zFUse [x:y] inclusive subscripts instead of [x-y] which has been removed)�PATTERN_WITH_SUBSCRIPTr�rR�intr\r_)rJr9�	subscript�m�idx�start�sep�endrrrr��s

z!InventoryManager._split_subscriptcCsJ|r|s|S|\}}|r<|dkr,t|�d}|||d�S||gSdS)z�
        Takes a list of hosts and a (start,end) tuple and returns the subset of
        hosts based on the subscript (which may be None to return all hosts).
        r�r�N)�len)rJrSr�r�r�rrrr�sz!InventoryManager._apply_subscriptc	sg}|�|jj��}|r8|D]}|�|jj|���q|r^�ddks^t�fdd�dD��r�|�|jj��}|r�|D]}|�|jj|�qv|s��tj	vr�|j�
��}|r�|�|�|�s|�s�dk�rd�}t�|�tj
dkr�t�|�ntj
d	k�rt|��|S)
z�
        Returns a list of host names matching the given pattern according to the
        rules explained above in _match_one_pattern.
        rr�c3s|]}|�vVqdSr'r)rZspecial�r9rrr*<rz6InventoryManager._enumerate_matches.<locals>.<genexpr>)�.�?�*�[r"z3Could not match supplied host pattern, ignoring: %sr_�error)r�rArRr�r��anyrSr#r]�	LOCALHOSTrPr\rpZHOST_PATTERN_MISMATCHr_r)	rJr9r:Zmatching_groupsZ	groupnameZmatching_hostsr[Zimplicit�msgrr�rr�.s,&


z#InventoryManager._enumerate_matchescCs*|�|�}t|�dkr&|tjvr&|g}|S)z* return a list of hostnames for a pattern r)r�r�r]r�)rJr9r�rrr�
list_hostsUs
zInventoryManager.list_hostscCst|jj���Sr')rtrArR�keysrQrrr�list_groups`szInventoryManager.list_groupscCs4|durdSt|t�s|g}tdd�|D��|_dS)z�
        Restrict list operations to the hosts given in restriction.  This is used
        to batch serial operations in main playbook code, don't use this for other
        reasons.
        Ncss|]}t|j�VqdSr')rr`r�rrrr*nrz5InventoryManager.restrict_to_hosts.<locals>.<genexpr>)r0r1r�rB)rJZrestrictionrrr�restrict_to_hostsds

z"InventoryManager.restrict_to_hostsc	Cs�|durd|_n�t|�}g}|D]�}|s*q |ddkr�t|dd��}tj�|�s^td|��tj�|�svtd|��t|��.}|�	dd�|�
��d	�D��Wd�q�1s�0Yq |�t
|��q ||_dS)
a0
        Limits inventory results to a subset of inventory that matches a given
        pattern, such as to select a given geographic of numeric slice amongst
        a previous 'hosts' selection that only select roles, or vice versa.
        Corresponds to --limit parameter to ansible-playbook
        Nr�@r�zUnable to find limit file %sz;Limit starting with "@" must be a file, not a directory: %scSsg|]}t|����qSr)rr/)r�lrrrr�rz+InventoryManager.subset.<locals>.<listcomp>�
)rCr(r
rqrrr�r�isfile�openr��readr5r#r)rJZsubset_patternZsubset_patternsr:rZb_limit_file�fdrrr�subsetps"
>zInventoryManager.subsetcCs
d|_dS)z! Do not restrict list operations N)rBrQrrr�remove_restriction�sz#InventoryManager.remove_restrictioncCs
i|_dSr')rErQrrr�clear_pattern_cache�sz$InventoryManager.clear_pattern_cachecCs�d}|�d�s|j�|�|r�|�d�}||jvrB|�|d�d}|j�|�}|��}t||�dt���}||kr|||_d}|�dg�}|D]<}	|	|j	vr�|j
�|	�}	d}|j	|	}
|
�|j|�r�d}q�|r�|��||d<d	S)
zX
        Helper function to add a new host to inventory based on a task result.
        Fr��	host_namer"TZ	host_varsrR�changedN)
r^rHr#rSrTZget_varsr�dictrgrRrArWrZ)rJZ	host_info�result_itemr�r�Znew_hostZ
new_host_varsZnew_host_combined_varsZ
new_groups�
group_nameZ	new_grouprrrr��s2




z!InventoryManager.add_dynamic_hostcCs4d}|�d�s|j�||f�|j�|j�}|durh|j|jjkrJ|j}n|�d�sdtd|j��ndS|�d�}|�dg�}||jvr�|�|�}|D]}||jvr�|�|�d}q�|j	j|}|D]$}	|j|	}
|
�
|�}|r�|s�d}q�||��v�r|�|�}||�
�v�r|�|�}|�r(|��||d<dS)	z�
        Helper function to add a group (if it does not exist), and to assign the
        specified host to that group.
        Fr�Nz!%s cannot be matched in inventoryrWZ
parent_groupsTr�)r^rIr#rSr`rNrrRrWrAZadd_child_groupr�rTZ
get_groupsrZ)rJrUr�r�Z	real_hostr�Zparent_group_namesr`rVZparent_group_nameZparent_group�newrrrr��s>










z"InventoryManager.add_dynamic_group)NTT)NN)F)F)r"FFN)r")"�__name__�
__module__�__qualname__�__doc__rM�propertyrNrRrSrTrWrXrZrPrbrGrerYr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr=�sB






\
94!'
(r=);Z
__future__rrr�typeZ
__metaclass__r�rqr~rr2r|�operatorrZrandomrZansiblerr]Zansible.errorsrr	r
Zansible.inventory.datarZansible.module_utils.sixrZansible.module_utils._textr
rZansible.parsing.utils.addressesrZansible.plugins.loaderrZansible.utils.helpersrZansible.utils.pathrZansible.utils.displayrZansible.utils.varsrZansible.vars.pluginsrr\ZIGNORED_ALWAYSZINVENTORY_IGNORE_PATTERNSZIGNORED_PATTERNSZINVENTORY_IGNORE_EXTSZIGNORED_EXTSr�rxrvr8r�r&r(�objectr=rrrr�<module>sB�
.