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

�)g�%�@s�ddlmZmZmZeZdZdZddlZddl	Z
ddlmZm
Z
ddlmZddlmZmZmZddlmZmZmZdd	lmZmZdd
lmZmZddlmZddl m!Z!dd
l"m#Z#m$Z$dZ%zddl&Z&dZ%Wne'y�Yn0dZ(zddl)Z)dZ(Wne'�yYn0dZ*zddl+Z+dZ*Wn:e'�y\zddl,Z+dZ*Wne'�yVYn0Yn0e!�Z-e%�r�e.e&d��r�Gdd�de&j/�Z0ee&j1e0�d�Z2ndd�Z2e%�r�e&j3Z4e&j5Z6ne*�r�e+j3Z4e+j6Z6dd�Z7Gdd�de�Z8dS)�)�absolute_import�division�print_functionaP
    name: toml
    version_added: "2.8"
    short_description: Uses a specific TOML file as an inventory source.
    description:
        - TOML based inventory format
        - File MUST have a valid '.toml' file extension
    notes:
        - >
          Requires one of the following python libraries: 'toml', 'tomli', or 'tomllib'
a�# fmt: toml
# Example 1
[all.vars]
has_java = false

[web]
children = [
    "apache",
    "nginx"
]
vars = { http_port = 8080, myvar = 23 }

[web.hosts]
host1 = {}
host2 = { ansible_port = 222 }

[apache.hosts]
tomcat1 = {}
tomcat2 = { myvar = 34 }
tomcat3 = { mysecret = "03#pa33w0rd" }

[nginx.hosts]
jenkins1 = {}

[nginx.vars]
has_java = true

# Example 2
[all.vars]
has_java = false

[web]
children = [
    "apache",
    "nginx"
]

[web.vars]
http_port = 8080
myvar = 23

[web.hosts.host1]
[web.hosts.host2]
ansible_port = 222

[apache.hosts.tomcat1]

[apache.hosts.tomcat2]
myvar = 34

[apache.hosts.tomcat3]
mysecret = "03#pa33w0rd"

[nginx.hosts.jenkins1]

[nginx.vars]
has_java = true

# Example 3
[ungrouped.hosts]
host1 = {}
host2 = { ansible_host = "127.0.0.1", ansible_port = 44 }
host3 = { ansible_host = "127.0.0.1", ansible_port = 45 }

[g1.hosts]
host4 = {}

[g2.hosts]
host4 = {}
N)�MutableMapping�MutableSequence)�partial)�AnsibleFileNotFound�AnsibleParserError�AnsibleRuntimeError)�to_bytes�	to_native�to_text)�string_types�	text_type)�AnsibleSequence�AnsibleUnicode)�BaseFileInventoryPlugin)�Display)�AnsibleUnsafeBytes�AnsibleUnsafeTextFT�TomlEncodercseZdZ�fdd�Z�ZS)�AnsibleTomlEncodercsVtt|�j|i|��|j�t|j�t�t|j�t	�t
|j�t	�t|j�t	�i�dS�N)�superr�__init__Z
dump_funcs�updater�get�listr�strrr)�self�args�kwargs��	__class__��B/usr/lib/python3.9/site-packages/ansible/plugins/inventory/toml.pyr�s�zAnsibleTomlEncoder.__init__)�__name__�
__module__�__qualname__r�
__classcell__r$r$r"r%r�sr)�encodercCs0trt�t|��Str$t�t|��Std��dS)NzTThe python "toml" or "tomli-w" library is required when using the TOML output format)�HAS_TOML�toml�dumps�convert_yaml_objects_to_native�
HAS_TOMLIW�tomli_wr
)�datar$r$r%�
toml_dumps�s�r2cCsRt|t�r tdd�|��D��St|t�r8dd�|D�St|t�rJt|�S|SdS)a�Older versions of the ``toml`` python library, and tomllib, don't have
    a pluggable way to tell the encoder about custom types, so we need to
    ensure objects that we pass are native types.

    Used with:
      - ``toml<0.10.0`` where ``toml.TomlEncoder`` is missing
      - ``tomli`` or ``tomllib``

    This function recurses an object and ensures we cast any of the types from
    ``ansible.parsing.yaml.objects`` into their native types, effectively cleansing
    the data before we hand it over to the toml library.

    This function doesn't directly check for the types from ``ansible.parsing.yaml.objects``
    but instead checks for the types those objects inherit from, to offer more flexibility.
    css|]\}}|t|�fVqdSr�r.)�.0�k�vr$r$r%�	<genexpr>��z1convert_yaml_objects_to_native.<locals>.<genexpr>cSsg|]}t|��qSr$r3)r4r6r$r$r%�
<listcomp>�r8z2convert_yaml_objects_to_native.<locals>.<listcomp>N)�
isinstance�dict�itemsrr)�objr$r$r%r.�s


r.cs>eZdZdZdd�Zdd�Zd�fdd�	Z�fd	d
�Z�ZS)�InventoryModuler,cCs^|dur&t|t�s&|j�d|�dS|j�|�}|dur>dS|��D�]\}}|dkr�t|t�svtd|t|�f��|��D]\}}|j�	|||�q~qF|dkr�t|t
�s�td|t|�f��|D]}|�|i�|j�||�q�qF|dk�rDt|t��std|t|�f��|��D](\}}|�
|�\}	}
|�|	|||
��qqF|j�d||f�qFdS)	Nz5Skipping '%s' as this is not a valid group definition�varszIInvalid "vars" entry for "%s" group, requires a dict, found "%s" instead.ZchildrenzMInvalid "children" entry for "%s" group, requires a list, found "%s" instead.�hostszJInvalid "hosts" entry for "%s" group, requires a dict, found "%s" instead.zYSkipping unexpected key "%s" in group "%s", only "vars", "children" and "hosts" are valid)r:r�displayZwarning�	inventory�	add_groupr<r	�typeZset_variabler�_parse_groupZ	add_childZ_expand_hostpatternZ_populate_host_vars)r�groupZ
group_data�keyr1�var�valueZsubgroupZhost_patternr@�portr$r$r%rE�sR

��

��

����zInventoryModule._parse_groupc
Cs$|rt|t�stdt|���t|j�|��}|j�|�sFtd|d��z"|j�	|�\}}t
t|dd��WSty�}z$td|t|�f|d��WYd}~n�d}~0t
tfy�}z$td|t|�f|d��WYd}~nFd}~0t�y}z$td	|t|�f|d��WYd}~n
d}~00dS)
NzInvalid filename: '%s'z Unable to retrieve file contents)�	file_nameZsurrogate_or_strict)�errorszTOML file (%s) is invalid: %s)Zorig_excz8An error occurred while trying to read the file '%s': %sz<An unexpected error occurred while parsing the file '%s': %s)r:rr	rr�loaderZ	path_dwimZpath_existsrZ_get_file_contents�
toml_loadsr
�TOMLDecodeError�IOError�OSError�	Exception)rrKZb_file_nameZb_dataZprivate�er$r$r%�
_load_file�s.���zInventoryModule._load_fileTc
s�tststd��tt|��|||�|��z|�|�}Wn,tyf}zt|��WYd}~n
d}~00|svtd��n|�	d�r�td��|D]}|�
|||�q�dS)z parses the inventory file zHThe TOML inventory plugin requires the python "toml", or "tomli" libraryNzParsed empty TOML fileZpluginz2Plugin configuration TOML file, not TOML inventory)�HAS_TOMLLIBr+r	rr>�parseZset_optionsrTrRrrE)rrBrM�path�cacher1rSZ
group_namer"r$r%rVs �

zInventoryModule.parsecs0tt|��|�r,tj�|�\}}|dkr,dSdS)Nz.tomlTF)rr>�verify_file�osrW�splitext)rrWrK�extr"r$r%rY%s
zInventoryModule.verify_file)T)	r&r'r(�NAMErErTrVrYr)r$r$r"r%r>�s
,r>)9Z
__future__rrrrDZ
__metaclass__Z
DOCUMENTATIONZEXAMPLESrZ�typing�t�collections.abcrr�	functoolsrZansible.errorsrr	r
Zansible.module_utils._textrrr
Zansible.module_utils.sixrrZansible.parsing.yaml.objectsrrZansible.plugins.inventoryrZansible.utils.displayrZansible.utils.unsafe_proxyrrr+r,�ImportErrorr/r0rUZtomllibZtomlirA�hasattrrrr-r2�loadsrNZTomlDecodeErrorrOr.r>r$r$r$r%�<module>sbG