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: //usr/lib/python3.9/site-packages/ansible/plugins/inventory/__pycache__/script.cpython-39.pyc
a

�)g��@s�ddlmZmZmZeZdZddlZddlZddl	m
Z
ddlmZm
Z
ddlmZddlmZmZddlmZdd	lmZe�ZGd
d�de�ZdS)�)�absolute_import�division�print_functiona�
    name: script
    version_added: "2.4"
    short_description: Executes an inventory script that returns JSON
    options:
      always_show_stderr:
        description: Toggle display of stderr even when script was successful
        version_added: "2.5.1"
        default: True
        type: boolean
        ini:
           - section: inventory_plugin_script
             key: always_show_stderr
        env:
           - name: ANSIBLE_INVENTORY_PLUGIN_SCRIPT_STDERR
    description:
        - The source provided must be an executable that returns Ansible inventory JSON
        - The source must accept C(--list) and C(--host <hostname>) as arguments.
          C(--host) will only be used if no C(_meta) key is present.
          This is a performance optimization as the script would be called per host otherwise.
    notes:
        - Enabled in configuration by default.
        - The plugin does not cache results because external inventory scripts are responsible for their own caching.
N)�Mapping)�AnsibleError�AnsibleParserError)�json_dict_bytes_to_unicode)�	to_native�to_text)�BaseInventoryPlugin)�DisplaycsNeZdZdZdZ�fdd�Z�fdd�Zd�fdd	�	Zd
d�Zdd
�Z	�Z
S)�InventoryModulezE Host inventory parser for ansible using external inventory scripts. Zscriptcstt|���t�|_dS�N)�superr
�__init__�set�_hosts)�self��	__class__��D/usr/lib/python3.9/site-packages/ansible/plugins/inventory/script.pyr4szInventoryModule.__init__cs�tt|��|�}|r�d}zFt|d��(}|�d�}|�d�r>d}Wd�n1sR0YWntypYn0t�|tj	�s�|s�d}|S)zP Verify if file is usable by this plugin, base does minimal accessibility check F�rb�s#!TN)
rr
�verify_file�open�read�
startswith�	Exception�os�access�X_OK)r�pathZvalidZshebang_presentZinv_fileZ
initial_charsrrrr:s

&zInventoryModule.verify_fileNcs�tt|��|||�|��|dg}�zXztj|tjtjd�}Wn>ty~}z&tdd�	|�t
|�f��WYd}~n
d}~00|��\}}	t
|�}t
|	p�d�}
|
r�|
�d�s�|
d7}
|j
dkr�td||
f��zt|d	d
�}Wn:t�y}z td�|t
|����WYd}~n
d}~00z|jj|dd
�}Wn<t�yl}z"td�|t
|�|
���WYd}~n
d}~00|	�r�|�d��r�|jjt|
�d�t|t��s�td�||
���d}
d}|��D]4\}
}|
dk�r�d|v�r�|d}n|�|
|��q�|jD]�}i}|du�r|�||�}nPz|�|i�}Wn>t�yh}z$td|t
|�f|d��WYd}~n
d}~00|�|g|��q�Wn2t�y�}ztt
|���WYd}~n
d}~00dS)Nz--list��stdout�stderr�problem running %s (%s)� ��
rz1Inventory script (%s) had an execution error: %s �strict)�errorszKInventory {0} contained characters that cannot be interpreted as UTF-8: {1}T)Z	json_onlyzEfailed to parse executable inventory script results from {0}: {1}
{2}Zalways_show_stderr)�msgzYfailed to parse executable inventory script results from {0}: needs to be a json dict
{1}�_metaZhostvarsz0Improperly formatted host information for %s: %s)Zorig_exc) rr
�parseZset_options�
subprocess�Popen�PIPE�OSErrorr�joinr	�communicate�endswith�
returncoderr
r�format�loader�loadZ
get_option�display�error�
isinstancer�items�_parse_groupr�get_host_variables�get�AttributeErrorZ_populate_host_vars)r�	inventoryr8r"�cache�cmd�sp�er$r%�err�dataZ	processed�groupZdata_from_metaZgdata�hostZgotrrrr.OsZ0
*,




.zInventoryModule.parsecs*|j�|�}t�t�s d�i�n"t�fdd�dD��sB|g�d��d�vr�t�dt�shtd|�f���dD]}|j�|�|j�	||�qpd�vr�t�dt�s�td|�f���d�
�D]\}}|j�|||�q�|d	k�r&t�t��r&d
�v�r&�d
D] }|j�|�}|j�||��qdS)N�hostsc3s|]}|�vVqdSrr)�.0�k�rHrr�	<genexpr>��z/InventoryModule._parse_group.<locals>.<genexpr>)rK�vars�children)rKrQz=You defined a group '%s' with bad data for the host list:
 %srQz9You defined a group '%s' with bad data for variables:
 %sr-rR)
rB�	add_groupr<�dict�any�listrr�addZadd_hostr=Zset_variableZ	add_child)rrIrH�hostnamerM�vZ
child_namerrNrr>�s(

 zInventoryModule._parse_groupc
Cs�|d|g}ztj|tjtjd�}Wn:ty\}z"tdd�|�|f��WYd}~n
d}~00|��\}}|��dkrziSzt|j	j
||d��WSty�td||f��Yn0dS)	zI Runs <script> --host <hostname>, to determine additional host variables z--hostr#r&r'Nr()�	file_namez.could not parse post variable response: %s, %s)r/r0r1r2rr3r4�striprr8r9�
ValueError)rr"rJrDrErF�outrGrrrr?�s
,z"InventoryModule.get_host_variables)N)�__name__�
__module__�__qualname__�__doc__�NAMErrr.r>r?�
__classcell__rrrrr
/sIr
)Z
__future__rrr�typeZ
__metaclass__Z
DOCUMENTATIONrr/�collections.abcrZansible.errorsrrZansible.module_utils.basicrZansible.module_utils._textr	r
Zansible.plugins.inventoryrZansible.utils.displayrr:r
rrrr�<module>s