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

�)g5D�@s�ddlmZmZmZeZdZdZddlZddl	Z	ddl
mZddlm
Z
ddlmZmZddlmZmZdd	lmZGd
d�de
�ZdS)�)�absolute_import�division�print_functionae
    name: ini
    version_added: "2.4"
    short_description: Uses an Ansible INI file as inventory source.
    description:
        - INI file based inventory, sections are groups or group related with special C(:modifiers).
        - Entries in sections C([group_1]) are hosts, members of the group.
        - Hosts can have variables defined inline as key/value pairs separated by C(=).
        - The C(children) modifier indicates that the section contains groups.
        - The C(vars) modifier indicates that the section contains variables assigned to members of the group.
        - Anything found outside a section is considered an 'ungrouped' host.
        - Values passed in the INI format using the C(key=value) syntax are interpreted differently depending on where they are declared within your inventory.
        - When declared inline with the host, INI values are processed by Python's ast.literal_eval function
          (U(https://docs.python.org/3/library/ast.html#ast.literal_eval)) and interpreted as Python literal structures
         (strings, numbers, tuples, lists, dicts, booleans, None). If you want a number to be treated as a string, you must quote it.
          Host lines accept multiple C(key=value) parameters per line.
          Therefore they need a way to indicate that a space is part of a value rather than a separator.
        - When declared in a C(:vars) section, INI values are interpreted as strings. For example C(var=FALSE) would create a string equal to C(FALSE).
          Unlike host lines, C(:vars) sections accept only a single entry per line, so everything after the C(=) must be the value for the entry.
        - Do not rely on types set during definition, always make sure you specify type with a filter when needed when consuming the variable.
        - See the Examples for proper quoting to prevent changes to variable type.
    notes:
        - Enabled in configuration by default.
        - Consider switching to YAML format for inventory sources to avoid confusion on the actual type of a variable.
          The YAML inventory plugin processes variable values consistently and correctly.
a�# fmt: ini
# Example 1
[web]
host1
host2 ansible_port=222 # defined inline, interpreted as an integer

[web:vars]
http_port=8080 # all members of 'web' will inherit these
myvar=23 # defined in a :vars section, interpreted as a string

[web:children] # child groups will automatically add their hosts to parent group
apache
nginx

[apache]
tomcat1
tomcat2 myvar=34 # host specific vars override group vars
tomcat3 mysecret="'03#pa33w0rd'" # proper quoting to prevent value changes

[nginx]
jenkins1

[nginx:vars]
has_java = True # vars in child groups override same in parent

[all:vars]
has_java = False # 'all' is 'top' parent

# Example 2
host1 # this is 'ungrouped'

# both hosts have same IP but diff ports, also 'ungrouped'
host2 ansible_host=127.0.0.1 ansible_port=44
host3 ansible_host=127.0.0.1 ansible_port=45

[g1]
host4

[g2]
host4 # same host as above, but member of 2 groups, will inherit vars from both
      # inventory hostnames are unique
N)�to_safe_group_name)�BaseFileInventoryPlugin)�AnsibleError�AnsibleParserError)�to_bytes�to_text)�shlex_splitcs�eZdZdZdZed�Zed�Z�fdd�Zd�fdd	�	Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Z�fdd�Zedd��Zdd�Z�ZS)�InventoryModulez�
    Takes an INI-format inventory file and builds a list of groups and subgroups
    with their associated hosts and variable settings.
    Zini)�;�#)�;�#cstt|���i|_d|_dS)N)�superr�__init__�patterns�	_filename��self��	__class__��A/usr/lib/python3.9/site-packages/ansible/plugins/inventory/ini.pyr`szInventoryModule.__init__Tc
stt|��|||�||_z�|jr4|j�|�\}}n>t|dd�}t|d��}|��}Wd�n1sh0Yzt	|dd��
�}	WnTty�g}	|�
�D]4}
|
r�|
d|jvr�|	�
d�q�|	�
t	|
dd��q�Yn0|�||	�Wn.t�y}zt|��WYd}~n
d}~00dS)N�surrogate_or_strict��errors�rbr�)rr�parser�loaderZ_get_file_contentsr	�open�readr
�
splitlines�UnicodeError�b_COMMENT_MARKERS�append�_parse�	Exceptionr)r�	inventoryr!�path�cacheZb_dataZprivate�b_pathZfh�data�line�errrr gs&&zInventoryModule.parsecCstd|j|jf|��dS)Nz%s:%d: )rr�lineno)r�messagerrr�_raise_error�szInventoryModule._raise_errorcCs�|��i}d}d}d|_|D�]
}|jd7_|��}|r|d|jvrNq|jd�|�}|�r.|��\}}t|�}|p~d}|dvr�d�|���}|�	d||f�||j
jvr�|d	kr�||vr�t|j||d
�||<|j
�|�||vr|d	kr||ddk�r|�
||�q||dd	kr||=qn.|�d
��r\|�d��r\|�	d|dd�|dk�r�|�|�\}	}
}|�|	|||
�q|d	k�r�|�|�\}}
|j
�|||
�q|dk�r|�|�}||j
jv�r||v�r�t|j|||gd�||<n||d�|�n|j
�||�q|�	d|�q|D]p}||}|dd	k�rltd||d|d|df��n2|ddk�r0td||d|d��|df���q0dS)zt
        Populates self.groups from the given array of lines. Raises an error on
        any parse failure.
        Z	ungrouped�hostsr��section)r4�children�vars�:z!Section [%s] has unknown type: %sr8)r/�state�namer:r7�[�]zFInvalid section entry: '%s'. Please make sure that there are no spaces� zDin the section entry, and that there are no other invalid characters)r/r:r;�parentsr?zEntered unhandled state: %sz:%s:%d: Section [%s:vars] not valid for undefined group: %sr/r;z9%s:%d: Section [%s:children] includes undefined group: %sN)�_compile_patternsr1�strip�_COMMENT_MARKERSr�match�groupsr�joinr3r*�dict�	add_group�_add_pending_children�
startswith�endswith�_parse_host_definitionZ_populate_host_vars�_parse_variable_definitionZset_variable�_parse_group_namer'�	add_childr�pop)rr+�linesZpending_declarations�	groupnamer:r/�m�titler4�port�	variables�k�v�child�gZdeclrrrr(�sh
	�	




"zInventoryModule._parsecCsN||dD]6}|j�||�||vr||ddkr|�||�q||=dS)Nr?r:r7)r*rNrH)r�group�pending�parentrrrrH�s
z%InventoryModule._add_pending_childrencCs0|jd�|�}|r|�d�S|�d|�dS)z�
        Takes a single line and tries to parse it as a group name. Returns the
        group name if successful, or raises an error.
        rQr5zExpected group name, got: %sN)rrCrZr3)rr/rRrrrrMs
z!InventoryModule._parse_group_namecCsBd|vr0dd�|�dd�D�\}}||�|�fS|�d|�dS)z�
        Takes a string and tries to parse it as a variable definition. Returns
        the key and value if successful, or raises an error.
        �=cSsg|]}|���qSr)rA)�.0r0rrr�
<listcomp>�z>InventoryModule._parse_variable_definition.<locals>.<listcomp>r5zExpected key=value, got: %sN)�split�_parse_valuer3)rr/rVrWrrrrL
sz*InventoryModule._parse_variable_definitionc

Cs�zt|dd�}Wn6tyF}z|�d||f�WYd}~n
d}~00|�|d�\}}i}|dd�D]8}d|vr�|�d|�|�dd�\}}	|�|	�||<qj|||fS)	z�
        Takes a single line and tries to parse it as a host definition. Returns
        a list of Hosts if successful, or raises an error.
        T)Zcommentsz&Error parsing host definition '%s': %sNrr5r]z4Expected key=value host variable assignment, got: %s)r�
ValueErrorr3�_expand_hostpatternrarb)
rr/�tokensr0�	hostnamesrTrU�trVrWrrrrKs(z&InventoryModule._parse_host_definitioncs`tt|��|�\}}|���d�r6|dur6td|��|D]}|��dkr:td|��q:||fS)z=
        do some extra checks over normal processing
        r9NzoInvalid host pattern '%s' supplied, ending in ':' is not allowed, this character is reserved to provide a port.z---zQInvalid host pattern '%s' supplied, '---' is normally a sign this is a YAML file.)rrrdrArJr)rZhostpatternrfrT�patternrrrrd?s�z#InventoryModule._expand_hostpatterncCs@zt�|�}Wn"ty Ynty0Yn0t|ddd�S)z�
        Attempt to transform the string value from an ini file into a basic python object
        (int, dict, list, unicode string, etc).
        Zpassthrur)Z	nonstringr)�astZliteral_evalrc�SyntaxErrorr
)rWrrrrbQszInventoryModule._parse_valuecCs<t�tddd�tj�|jd<t�tddd�tj�|jd<dS)z|
        Compiles the regular expressions required to parse the inventory and
        stores them in self.patterns.
        a�^\[
                    ([^:\]\s]+)             # group name (see groupname below)
                    (?::(\w+))?             # optional : and tag name
                \]
                \s*                         # ignore trailing whitespace
                (?:\#.*)?                   # and/or a comment till the
                $                           # end of the line
            rrr6z�^
                ([^:\]\s]+)
                \s*                         # ignore trailing whitespace
                (?:\#.*)?                   # and/or a comment till the
                $                           # end of the line
            rQN)�re�compiler
�Xrrrrrr@cs��
��z!InventoryModule._compile_patterns)T)�__name__�
__module__�__qualname__�__doc__�NAME�	frozensetrBr&rr r3r(rHrMrLrKrd�staticmethodrbr@�
__classcell__rrrrrWs $l!
r)Z
__future__rrr�typeZ
__metaclass__Z
DOCUMENTATIONZEXAMPLESrirkZansible.inventory.grouprZansible.plugins.inventoryrZansible.errorsrrZansible.module_utils._textr	r
Zansible.utils.shlexrrrrrr�<module>s+