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/cli/__pycache__/inventory.cpython-39.pyc
a

�)g@�@s�ddlmZmZmZeZddlmZddlZddl	Z	ddl
mZddl
m
Z
ddlmZddlmZmZddlmZmZmZdd	lmZdd
lmZddlmZmZe�Ze gd��Z!Gd
d�de�Z"ddd�Z#e$dkr�e#�dS)�)�absolute_import�division�print_function)�CLIN)�	constants)�context)�option_helpers)�AnsibleError�AnsibleOptionsError)�to_bytes�	to_native�to_text)�combine_vars)�Display)�get_vars_from_inventory_sources�get_vars_from_path)Zansible_diff_modeZansible_config_fileZ
ansible_factsZ
ansible_forksZansible_inventory_sourcesZ
ansible_limitZansible_playbook_pythonZansible_run_tagsZansible_skip_tagsZansible_verbosityZansible_versionZ
inventory_dirZinventory_fileZinventory_hostnameZinventory_hostname_short�groupsZgroup_namesZomitZplaybook_dircs�eZdZdZdZddd�Z�fdd�Z�fdd	�Z�fd
d�Z�fdd
�Z	e
dd��Zdd�Zdd�Z
dd�Ze
dd��Ze
dd��Ze
dd��Ze
d)dd��Zd*dd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Z�ZS)+�InventoryCLIzE used to display or dump the configured inventory as Ansible sees it zansible-inventoryzHThe name of a host to match in the inventory, relevant when using --listzAThe name of a group in the inventory, relevant when using --graph)�host�groupcs&tt|��|�d|_d|_d|_dS�N)�superr�__init__�vm�loader�	inventory)�self�args��	__class__��9/usr/lib/python3.9/site-packages/ansible/cli/inventory.pyr9szInventoryCLI.__init__csPtt|�jddd�t�|j�t�|j�t�|j�t�|j�|jj	ddt
jtjdd�|jj	dt
jtjd	�|jj	d
ddd�|j�
d
d�}|j	dddddd�|j	dddddd�|j	dddddd�|j�
|�|jj	ddddddd�|jj	d ddd!d"d�|jj	d#ddd$d%d�|jj	d&dtjd'd(d�|jj	d)dd*d+d,�dS)-Nz#usage: %prog [options] [host|group]zWShow Ansible inventory information, by default it uses the inventory script JSON format)�usageZdescz-lz--limit�?)�help�action�nargsz--list-hosts)r$r%rz
host|group)�metavarr&ZActionsz6One of following must be used on invocation, ONLY ONE!z--list�
store_trueF�listz0Output all hosts info, works as inventory script)r%�default�destr$z--host�storerz4Output specific host info, works as inventory scriptz--graph�graphzJcreate inventory graph, if supplying pattern it must be a valid group namez-yz--yaml�yamlz<Use YAML format instead of default JSON, ignored for --graphz--toml�tomlz<Use TOML format instead of default JSON, ignored for --graphz--vars�	show_varsz;Add vars to graph display, ignored unless used with --graphz--export�exportz�When doing an --list, represent in a way that is optimized for export,not as an accurate representation of how Ansible has processed itz--output�output_filezHWhen doing --list, send the inventory to a file instead of to the screen)r*r+r$)rr�init_parser�opt_helpZadd_inventory_options�parserZadd_vault_optionsZadd_basedir_optionsZadd_runtask_options�add_argument�argparse�SUPPRESSZUnrecognizedArgument�add_argument_group�CZINVENTORY_EXPORT)r�action_grouprr r!r3@sB
�������zInventoryCLI.init_parsercs�tt|��|�}|jt_|�|�d}|j|j|jfD]}|r6|d7}q6|dkrZt	d��n|dkrjt	d��|j
rz|j
|_nd|_|S)Nr�zTNo action selected, at least one of --host, --graph or --list needs to be specified.z]Conflicting options used, only one of --host, --graph or --list can be used at the same time.�all)rr�post_process_args�	verbosity�displayZvalidate_conflictsr)rr-r
r�pattern)r�options�used�optrr r!r>is



zInventoryCLI.post_process_argsc
s�tt|���|��\|_|_|_d}tjdrr|j�	tjd�}t
|�dkrVtd��|j|dd�}|�
|�}nhtjdr�|��}nTtjdr�|�d�}tjd	r�|�|�}n tjd
r�|�|�}n
|�|�}|�
|�}|�r�tjd}|dur�t�|�n�zBtt|�d��}|�t|��Wd�n1�s40YWnBttf�y�}z$td
t|�t|�f��WYd}~n
d}~00t�d�t�d�dS)Nrr<z5You must pass a single valid host to --host parameterr�rr-r)r=r.r/r2�wbz,Unable to write to destination file (%s): %s)rr�runZ
_play_prereqsrrrr�CLIARGS�	get_hosts�lenr
�_get_host_variables�dump�inventory_graph�
_get_group�yaml_inventory�toml_inventory�json_inventoryr@�openr�write�OSError�IOErrorr	r�sys�exit)r�results�hosts�myvars�topZoutfile�f�err r!rG�s<









2.
zInventoryCLI.runcCsDtjdr8ddl}ddlm}t|j||ddd��}�ntjdr�ddlm}z||�}Wndt	y�}zt
d	|��WYd}~n>d}~0ty�}zt
d
|jd��WYd}~n
d}~00n~ddl
}ddlm}z|j||ddddd
�}WnNt	�y>}z4|j||ddddd
�}t�dt|��WYd}~n
d}~00|S)Nr.r)�
AnsibleDumperFT)ZDumperZdefault_flow_styleZ
allow_unicoder/)�
toml_dumpszLThe source inventory contains a value that cannot be represented in TOML: %saThe source inventory contains a non-string key (%s) which cannot be represented in TOML. The specified key will need to be converted to a string. Be aware that if your playbooks expect this key to be non-string, your playbooks will need to be modified to support this change.)�AnsibleJSONEncoder�)�clsZ	sort_keys�indentZpreprocess_unsafeZensure_asciiz?Could not sort JSON output due to issues while sorting keys: %s)rrHr.Zansible.parsing.yaml.dumperr^r
rLZansible.plugins.inventory.tomlr_�	TypeErrorr	�KeyErrorr�jsonZansible.parsing.ajsonr`�dumpsr@Zwarningr)�stuffr.r^rXr_r]rfr`r r r!rL�s4

���(zInventoryCLI.dumpcCsj|��}t|t|j|jj|gd��}tjdrLt|t|jtjd|gd��}|j	dkr`|j	|d<|�
|�S)Nr=�basedirr<Zansible_group_priority)�get_varsrrrr�_sourcesrrHr�priority�_remove_internal)rr�resr r r!�_get_group_variables�s


z!InventoryCLI._get_group_variablescCsttjdrX|��}t|t|j|jj|gd��}tjdrjt|t|jtjd|gd��}n|j	j|ddd�}|�
|�S)Nr1r=riF)rZinclude_hostvarsZstage)rrHrjrrrrrkrrrm)rr�hostvarsr r r!rK�s

 z InventoryCLI._get_host_variablescCs|jj�|�}|Sr)rr�get)r�gnamerr r r!rN�szInventoryCLI._get_groupcCstD]}||vr||=q|Sr)�
INTERNAL_VARS)rLZinternalr r r!rm�szInventoryCLI._remove_internalcCs$dD]}||vr||s||=qdS)N)rY�vars�childrenr )rL�xr r r!�
_remove_empty�szInventoryCLI._remove_emptycCs8g}t|���D]"\}}|�t�d||f|��q|S)Nz	{%s = %s})�sorted�items�appendr�_graph_name)rL�depth�result�name�valr r r!�
_show_varsszInventoryCLI._show_varsrcCs|rd|d|}|S)Nz  |z--%sr )r~r|r r r!r{	szInventoryCLI._graph_namecCs�|�d|j|�g}|d}|jD]}|�|�||��q"|jdkr�|jD]>}|�|�|j|��tjdrJ|�|�	|�
|�|d��qJtjdr�|�|�	|�|�|��|S)Nz@%s:r<r=r0)r{r~�child_groups�extend�_graph_grouprYrzrrHr�rKro)rrr|r}Zkidrr r r!r�s




zInventoryCLI._graph_groupcCs0|�tjd�}|r$d�|�|��Std��dS)NrA�
z3Pattern must be valid group name when using --graph)rNrrH�joinr�r
)rZstart_atr r r!rM!szInventoryCLI.inventory_graphcsbt�����fdd���|�}dii|d<�j��}|D]$}��|�}|r8||dd|j<q8|S)Ncs�i}i||j<|jdkr2dd�|jD�||jd<g||jd<|jD]>}||jd�|j�|j�vrF|��|����|j�qFtjdr���|�||jd<��	||j�||js�||j=|S)Nr=cSsg|]
}|j�qSr )r~)�.0�hr r r!�
<listcomp>1�zEInventoryCLI.json_inventory.<locals>.format_group.<locals>.<listcomp>rYrur1rt)
r~rYr�rz�update�addrrHrorw)rrX�subgroup��format_group�seenrr r!r�-s 





z1InventoryCLI.json_inventory.<locals>.format_grouprpZ_meta)�setrrIrKr~)rr[rXrYrZhvarsr r�r!rQ)s

zInventoryCLI.json_inventorycsg����fdd���|�S)Ncs�i}i||j<i||jd<|jD]&}|jdkr"||jd��|��q"i||jd<|jdkr�|jD]>}i}|j�vr���|j��j|d�}|||jd|j<qhtjdrΈ�|�}|r�|||jd<��	||j�|S)Nrur=rYrEr1rt)
r~r�r�rYrzrKrrHrorw)rrXr�r�rZ�gvarsr�r r!r�Qs(







z1InventoryCLI.yaml_inventory.<locals>.format_groupr )rr[r r�r!rOMszInventoryCLI.yaml_inventorycs<t��ttdd�|jD��������fdd���|�}|S)Ncss|]}|jdkr|jVqdS)�	ungroupedN)r~rY)r��gr r r!�	<genexpr>tr�z.InventoryCLI.toml_inventory.<locals>.<genexpr>c	s,i}i||j<g||jd<|jD]B}|jdkr6�s6q"|jdkrV||jd�|j�|��|��q"|jdkr�|jD]l}|j�vr���|j��j|d�}ni}z|||jd|j<Wqvty�|j|i||jd<Yqv0qvtj	d�r��
|�||jd<��||j�||j�s(||j=|S)Nrur�r=rErYr1rt)r~r�rzr�rYr�rKrerrHrorw)rrXr�rZ	host_vars�r�Z
has_ungroupedr�rr r!r�vs2





z1InventoryCLI.toml_inventory.<locals>.format_group)r��bool�nextr�)rr[rXr r�r!rPrs
!zInventoryCLI.toml_inventory)r)r)�__name__�
__module__�__qualname__�__doc__r~Z	ARGUMENTSrr3r>rG�staticmethodrLrorKrNrmrwr�r{r�rMrQrOrP�
__classcell__r r rr!r1s6�)-
 



$%rcCst�|�dSr)rZcli_executor)rr r r!�main�sr��__main__)N)%Z
__future__rrr�typeZ
__metaclass__Zansible.clirrVr7Zansiblerr:rZansible.cli.argumentsrr4Zansible.errorsr	r
Zansible.module_utils._textrrr
Zansible.utils.varsrZansible.utils.displayrZansible.vars.pluginsrrr@�	frozensetrsrr�r�r r r r!�<module>s(m