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__/data.cpython-39.pyc
a

�)g�)�@s�ddlmZmZmZeZddlZddlmZ	ddl
mZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZe�ZGdd�de�ZdS)
�)�absolute_import�division�print_functionN)�	constants)�AnsibleError)�Group)�Host)�string_types)�Display)�combine_vars)�basedirc@szeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zddd�Zdd�Z
dd�Zdd�Zdd�ZdS)�
InventoryDataz�
    Holds inventory data (host and group objects).
    Using it's methods should guarantee expected relationships and data.
    cCsHi|_i|_i|_d|_d|_g|_dD]}|�|�q(|�dd�dS)N)�all�	ungroupedrr)�groups�hosts�_groups_dict_cache�	localhost�current_source�processed_sources�	add_group�	add_child)�self�group�r�:/usr/lib/python3.9/site-packages/ansible/inventory/data.py�__init__*szInventoryData.__init__cCs$d|_|j|j|j|j|jd�}|S)N)rr�local�sourcer)rrrrrr�r�datarrr�	serialize=s�zInventoryData.serializecCsFi|_|�d�|_|�d�|_|�d�|_|�d�|_|�d�|_dS)Nrrrrr)r�getrrrrrrrrr�deserializeHszInventoryData.deserializecCs\|jr|j}nJt|�}d|_d|_tj}|s:d}t�d�|�d|�|�dd�||_|S)Nz	127.0.0.1Tz/usr/bin/pythonz�Unable to determine python interpreter from sys.executable. Using /usr/bin/python default. You can correct this by setting ansible_python_interpreter for localhostZansible_python_interpreterZansible_connectionr)	rr�address�implicit�sys�
executable�display�warning�set_variable)r�patternZnew_hostZ	py_interprrr�_create_implicit_localhostPs
z(InventoryData._create_implicit_localhostc	CsFt�d�d|_t�}|jD]:}|j|}|�|j�|jdkr|��s|�d|j�qt�}|j	�
�D]�}|�|j�|��}|jd|vr�t|��t|jd|jdg��r�|jd�
|�n:|js�t|�}|dks�|dkr�|jd|vr�|�d|j�|jrht|jd��|j�|_qh|�|�D]}t�d|��q&i|_dS)z1 Ensure inventory basic rules, run after updates z(Reconcile groups and hosts in inventory.Nrrr�z,Found both group and host with same name: %s)r(�debugr�setr�add�nameZ
get_ancestorsrr�valuesZ
get_groups�
difference�remove_hostr%�lenrZget_vars�vars�intersectionr)r)	rZgroup_names�grZ
host_names�hostZmygroups�lengthZconflictrrr�reconcile_inventoryhs0


"z!InventoryData.reconcile_inventorycCs.|j�|d�}|dur*|tjvr*|�|�}|S)z; fetch host object using name deal with implicit localhost N)rr"�C�	LOCALHOSTr,)r�hostnameZ
matching_hostrrr�get_host�s
zInventoryData.get_hostcCs�|rxt|t�s"tdt|�|f��||jvrht|�}|j|jvr`||j|j<i|_t�	d|�|j}q�t�	d|�ntd|��|S)zM adds a group to inventory if not there already, returns named actually used z@Invalid group name supplied, expected a string but got %s for %szAdded group %s to inventoryzgroup %s already in inventoryz+Invalid empty/false group name provided: %s)
�
isinstancer	r�typerrr1rr(r.)rrr8rrrr�s

zInventoryData.add_groupcCsJ||jvr&|j|=t�d|�i|_|jD]}|j|}|�|�q,dS)NzRemoved group %s from inventory)rr(r.rr�remove_group)rrr9�hrrrrB�s


zInventoryData.remove_groupNcCsR|�rBt|t�s$tdt|�|f��d}|rN||jvrB|j|}ntd|��||jv�rt||�}||j|<|jr�|�|d|j�|�|dt	|j��n|�|dd�|�|dd�t
�d|�|tj
v�r|jdur�|j||_t
�d|�nt
�d||jjf�n
|j|}|�rN|�|�i|_t
�d	||f�ntd
|��|S)zD adds a host to inventory and possibly a group if not there already z?Invalid host name supplied, expected a string but got %s for %sNz$Could not find group %s in inventoryZinventory_fileZ
inventory_dirzAdded host %s to inventoryzSet default localhost to %szMA duplicate localhost-like entry was found (%s). First found localhost was %szAdded host %s to group %sz$Invalid empty host name provided: %s)r@r	rrArrrrr*rr(r.r<r=rZvvvvr)r1�add_hostr)rr9r�portr8rCrrrrD�s:






zInventoryData.add_hostcCs:|j|jvr|j|j=|jD]}|j|}|�|�qdS)N)r1rrr4)rr9rr8rrrr4�s



zInventoryData.remove_hostcCsZ||jvr|j|}n"||jvr,|j|}ntd|��|�||�t�d||f�dS)z) sets a variable for an inventory object z)Could not identify group or host named %sz
set %s for %sN)rrrr*r(r.)rZentityZvarname�valueZ
inv_objectrrrr*�s

zInventoryData.set_variablecCs�d}||jvrv|j|}||jvr4|�|j|�}n(||jvrP|�|j|�}ntd|��i|_t�d||f�ntd|��|S)z Add host or group to group Fz %s is not a known host nor groupzGroup %s now contains %sz%s is not a known group)rZadd_child_grouprrDrrr(r.)rr�childZaddedr8rrrrs



zInventoryData.add_childcCs8|js2|j��D] \}}dd�|��D�|j|<q|jS)z�
        We merge a 'magic' var 'groups' with group name keys and hostname list values into every host variable set. Cache for speed.
        cSsg|]
}|j�qSr)r1)�.0rCrrr�
<listcomp>�z1InventoryData.get_groups_dict.<locals>.<listcomp>)rr�itemsZ	get_hosts)rZ
group_namerrrr�get_groups_dictszInventoryData.get_groups_dict)NN)�__name__�
__module__�__qualname__�__doc__rr!r#r,r;r?rrBrDr4r*rrLrrrrr
$s,
-	
r
)Z
__future__rrrrAZ
__metaclass__r&Zansiblerr<Zansible.errorsrZansible.inventory.grouprZansible.inventory.hostrZansible.module_utils.sixr	Zansible.utils.displayr
Zansible.utils.varsrZansible.utils.pathrr(�objectr
rrrr�<module>s