Dashboard
PHP:
8.2.30
OS:
Linux
User:
dh_nv8b2m
/
/
usr
/
local
/
lib
/
python3.10
/
dist-packages
/
ansible
/
plugins
/
inventory
/
__pycache__
📤 Upload
📝 New File
📁 New Folder
Close
Editing: ini.cpython-310.pyc
o O�h�D � @ s� d dl mZ dZdZd dlZd dlZd dlZd dlmZ d dl m Z d dlmZm Z d dlmZmZ d d lmZ G d d� de �ZdS )� )�annotationsae 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_splitc s� e Zd ZdZdZed�Zed�Z� fdd�Zd� fdd � Z d d� Z dd � Zdd� Zdd� 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. �ini)�;�#)� ;� #c s t t| ��� i | _d | _d S )N)�superr �__init__�patterns� _filename��self�� __class__� �H/usr/local/lib/python3.10/dist-packages/ansible/plugins/inventory/ini.pyr ` s zInventoryModule.__init__Tc s t t| ��|||� || _zi| jr| j�|�\}}nt|dd�}t|d��}|�� }W d � n1 s4w Y z t |dd�� � } W n* tym g } |� � D ]} | ra| d | jv ra| � d� qP| � t | dd�� qPY nw | �|| � W d S ty� } zt|��d }~ww )N�surrogate_or_strict��errors�rbr � )r r �parser �loader�_get_file_contentsr �open�readr � splitlines�UnicodeError�b_COMMENT_MARKERS�append�_parse� Exceptionr )r � inventoryr �path�cache�b_data�private�b_path�fh�data�line�er r r r g s0 ��� ��zInventoryModule.parsec C s t d| j| jf | ��)Nz%s:%d: )r r �lineno)r �messager r r �_raise_error� s zInventoryModule._raise_errorc C s� | � � i }d}d}d| _|D ]�}| jd7 _|�� }|r%|d | jv r&q| jd �|�}|r�|�� \}}t|�}|p=d}|dvrRd�|�� �}| � d||f � || j jvrp|d krj||vrjt| j||d �||<