관리-도구
편집 파일: toml.cpython-39.pyc
a �����)g�%����������������������@���s���d�dl�mZmZmZ�eZdZdZd�dlZd�dl Z d�dlmZm Z �d�dlmZ�d�dlmZmZmZ�d�dlmZmZmZ�d�d lmZmZ�d�d lmZmZ�d�dlmZ�d�dl m!Z!�d�d l"m#Z#m$Z$�dZ%zd�dl&Z&dZ%W�n�e'y����Y�n0�dZ(zd�dl)Z)dZ(W�n�e'�y���Y�n0�dZ*zd�dl+Z+dZ*W�n:�e'�y\���zd�dl,Z+dZ*W�n�e'�yV���Y�n0�Y�n0�e!��Z-e%�r�e.e&d��r�G�dd��de&j/�Z0ee&j1e0��d�Z2ndd��Z2e%�r�e&j3Z4e&j5Z6ne*�r�e+j3Z4e+j6Z6dd��Z7G�dd��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�TomlEncoderc�����������������������s���e�Zd�Z��fdd�Z���ZS�)�AnsibleTomlEncoderc��������������������sV���t�t|��j|i�|���|�j�t|�j�t�t|�j�t �t |�j�t �t|�j�t �i��d�S��N)�superr����__init__Z dump_funcs�updater����get�listr����strr���r���)�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�������s���r���)�encoderc�����������������C���s0���t�rt�t|���S�tr$t�t|���S�td��d�S�)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�����r2���c�����������������C���sR���t�|�t�r tdd��|����D���S�t�|�t�r8dd��|�D��S�t�|�t�rJt|��S�|�S�dS�)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. c�����������������s���s���|�]\}}|t�|�fV��qd�S�r����r.���)�.0�k�vr$���r$���r%���� <genexpr>���������z1convert_yaml_objects_to_native.<locals>.<genexpr>c�����������������S���s���g�|�]}t�|��qS�r$���r3���)r4���r6���r$���r$���r%���� <listcomp>����r8���z2convert_yaml_objects_to_native.<locals>.<listcomp>N)� isinstance�dict�itemsr���r���)�objr$���r$���r%���r.�������s���� r.���c�����������������������s>���e�Zd�ZdZdd��Zdd��Zd��fdd� Z��fd d �Z���ZS�)�InventoryModuler,���c�����������������C���s^��|d�ur&t�|t�s&|�j�d|���d�S�|�j�|�}|d�u�r>d�S�|���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���qFd�S�) 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 ����typeZset_variabler����_parse_groupZ add_childZ_expand_hostpatternZ_populate_host_vars)r����groupZ group_data�keyr1����var�valueZsubgroupZhost_patternr@����portr$���r$���r%���rE�������sR���� �� �� ����zInventoryModule._parse_groupc�������������� ���C���s$��|rt�|t�stdt|����t|�j�|��}|�j�|�sFtd|d��z"|�j� |�\}}t t|dd��W�S��ty��}�z$td|t|�f�|d��W�Y�d�}~n�d�}~0��t tfy��}�z$td|t|�f�|d��W�Y�d�}~nFd�}~0��t�y�}�z$td |t|�f�|d��W�Y�d�}~n d�}~0�0�d�S�) 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:���r���r ���r���r����loaderZ path_dwimZpath_existsr���Z_get_file_contents� toml_loadsr ����TOMLDecodeError�IOError�OSError� Exception)r���rK���Zb_file_nameZb_dataZprivate�er$���r$���r%���� _load_file����s.�������zInventoryModule._load_fileTc�������������� ������s����t�ststd��tt|���|||��|�����z|��|�}W�n,�tyf�}�zt|��W�Y�d}~n d}~0�0�|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 ���r���r>����parseZset_optionsrT���rR���r���rE���)r���rB���rM����path�cacher1���rS���Z group_namer"���r$���r%���rV�����s ����� zInventoryModule.parsec��������������������s0���t�t|���|�r,tj�|�\}}|dkr,dS�dS�)Nz.tomlTF)r���r>����verify_file�osrW����splitext)r���rW���rK����extr"���r$���r%���rY���%��s ����zInventoryModule.verify_file)T) r&���r'���r(����NAMErE���rT���rV���rY���r)���r$���r$���r"���r%���r>�������s ���,r>���)9Z __future__r���r���r���rD���Z __metaclass__Z DOCUMENTATIONZEXAMPLESrZ����typing�t�collections.abcr���r���� functoolsr���Zansible.errorsr���r ���r ���Zansible.module_utils._textr���r���r ���Zansible.module_utils.sixr���r���Zansible.parsing.yaml.objectsr���r���Zansible.plugins.inventoryr���Zansible.utils.displayr���Zansible.utils.unsafe_proxyr���r���r+���r,����ImportErrorr/���r0���rU���ZtomllibZtomlirA����hasattrr���r���r-���r2����loadsrN���ZTomlDecodeErrorrO���r.���r>���r$���r$���r$���r%����<module>���sb���G