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

�)g��@slddlmZmZmZeZdZdZddlZddl	m
Z
ddlmZ
ddlmZddlmZGd	d
�d
e�ZdS)�)�absolute_import�division�print_functiona$
    name: generator
    version_added: "2.6"
    short_description: Uses Jinja2 to construct hosts and groups from patterns
    description:
        - Uses a YAML configuration file with a valid YAML or C(.config) extension to define var expressions and group conditionals
        - Create a template pattern that describes each host, and then use independent configuration layers
        - Every element of every layer is combined to create a host for every layer combination
        - Parent groups can be defined with reference to hosts and other groups using the same template variables
    options:
      plugin:
         description: token that ensures this is a source file for the 'generator' plugin.
         required: True
         choices: ['ansible.builtin.generator', 'generator']
      hosts:
        description:
          - The C(name) key is a template used to generate
            hostnames based on the C(layers) option. Each variable in the name is expanded to create a
            cartesian product of all possible layer combinations.
          - The C(parents) are a list of parent groups that the host belongs to. Each C(parent) item
            contains a C(name) key, again expanded from the template, and an optional C(parents) key
            that lists its parents.
          - Parents can also contain C(vars), which is a dictionary of vars that
            is then always set for that variable. This can provide easy access to the group name. E.g
            set an C(application) variable that is set to the value of the C(application) layer name.
      layers:
        description:
          - A dictionary of layers, with the key being the layer name, used as a variable name in the C(host)
            C(name) and C(parents) keys. Each layer value is a list of possible values for that layer.
a�
    # inventory.config file in YAML format
    # remember to enable this inventory plugin in the ansible.cfg before using
    # View the output using `ansible-inventory -i inventory.config --list`
    plugin: ansible.builtin.generator
    hosts:
        name: "{{ operation }}_{{ application }}_{{ environment }}_runner"
        parents:
          - name: "{{ operation }}_{{ application }}_{{ environment }}"
            parents:
              - name: "{{ operation }}_{{ application }}"
                parents:
                  - name: "{{ operation }}"
                  - name: "{{ application }}"
              - name: "{{ application }}_{{ environment }}"
                parents:
                  - name: "{{ application }}"
                    vars:
                      application: "{{ application }}"
                  - name: "{{ environment }}"
                    vars:
                      environment: "{{ environment }}"
          - name: runner
    layers:
        operation:
            - build
            - launch
        environment:
            - dev
            - test
            - prod
        application:
            - web
            - api
N)�product)�	constants)�AnsibleParserError)�BaseInventoryPlugincsNeZdZdZdZ�fdd�Z�fdd�Zdd�Zd	d
�Zd�fdd
�	Z	�Z
S)�InventoryModulez> constructs groups and vars using Jinja2 template expressions �	generatorcstt|���dS�N)�superr	�__init__)�self��	__class__��G/usr/lib/python3.9/site-packages/ansible/plugins/inventory/generator.pyr
XszInventoryModule.__init__cs@d}tt|��|�r<tj�|�\}}|r8|dgtjvr<d}|S)NFz.configT)rr	�verify_file�os�path�splitext�CZYAML_FILENAME_EXTENSIONS)rrZvalid�	file_name�extrrrr\szInventoryModule.verify_filecCs||j_|j�|�Sr)ZtemplarZavailable_variablesZdo_template)r�patternZ	variablesrrr�templategszInventoryModule.templatec

Cs�|D]�}z|�|d|�}Wn&ttfyBtd|d��Yn0||jvrX|�|�|j|}|�di���D]\}}	|�||�|	|��qr|�	||�|�
|||�dg�|�qdS)N�namez,Element %s has a parent with no name element�vars�parents)r�AttributeError�
ValueErrorr�groups�	add_group�get�itemsZset_variableZ	add_child�add_parents)
r�	inventory�childr�
template_vars�parentZ	groupname�group�k�vrrrr%ks


zInventoryModule.add_parentsFc	s�tt|�j||||d�|�|�}t|d���}|D]j}t�}t|d���D]\}	}
||	||
<qP|�	|dd|�}|�
|�|�|||d�dg�|�q6dS)z parses the inventory file )�cacheZlayers�hostsrrN)
rr	�parseZ_read_config_datar�values�dict�	enumerate�keysrZadd_hostr%r#)rr&�loaderrr-ZconfigZtemplate_inputs�itemr(�i�key�hostrrrr/ys

zInventoryModule.parse)F)�__name__�
__module__�__qualname__�__doc__�NAMEr
rrr%r/�
__classcell__rrrrr	Ssr	)Z
__future__rrr�typeZ
__metaclass__Z
DOCUMENTATIONZEXAMPLESr�	itertoolsrZansiblerrZansible.errorsrZansible.plugins.inventoryrr	rrrr�<module>s$