HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/roster/__pycache__/ansible.cpython-310.pyc
o

�N�g&�@sldZddlZddlZddlZddlZddlmZdddddd	d
�ZdZ	dd
�Z
ddd�Zdd�Zdd�Z
dS)aE
Read in an Ansible inventory file or script.

Flat inventory files should be in the regular ansible inventory format.

.. code-block:: ini

    # /tmp/example_roster
    [servers]
    salt.gtmanfred.com ansible_ssh_user=gtmanfred ansible_ssh_host=127.0.0.1 ansible_ssh_port=22 ansible_ssh_pass='password' ansible_sudo_pass='password'

    [desktop]
    home ansible_ssh_user=gtmanfred ansible_ssh_host=12.34.56.78 ansible_ssh_port=23 ansible_ssh_pass='password' ansible_sudo_pass='password'

    [computers:children]
    desktop
    servers

    [computers:vars]
    http_port=80

then salt-ssh can be used to hit any of them

.. code-block:: bash

    [~]# salt-ssh --roster=ansible --roster-file=/tmp/example_roster -N all test.ping
    salt.gtmanfred.com:
        True
    home:
        True
    [~]# salt-ssh --roster=ansible --roster-file=/tmp/example_roster -N desktop test.ping
    home:
        True
    [~]# salt-ssh --roster=ansible --roster-file=/tmp/example_roster -N computers test.ping
    salt.gtmanfred.com:
        True
    home:
        True
    [~]# salt-ssh --roster=ansible --roster-file=/tmp/example_roster salt.gtmanfred.com test.ping
    salt.gtmanfred.com:
        True

There is also the option of specifying a dynamic inventory, and generating it on the fly

.. code-block:: bash

    #!/bin/bash
    # filename: /etc/salt/hosts
    echo '{
        "servers": [
            "salt.gtmanfred.com"
        ],
        "desktop": [
            "home"
        ],
        "computers": {
            "hosts": [],
            "children": [
                "desktop",
                "servers"
            ],
            "vars": {
                "http_port": 80
            }
        },
        "_meta": {
            "hostvars": {
                "salt.gtmanfred.com": {
                    "ansible_ssh_user": "gtmanfred",
                    "ansible_ssh_host": "127.0.0.1",
                    "ansible_sudo_pass": "password",
                    "ansible_ssh_pass": "password",
                    "ansible_ssh_port": 22
                },
                "home": {
                    "ansible_ssh_user": "gtmanfred",
                    "ansible_ssh_host": "12.34.56.78",
                    "ansible_sudo_pass": "password",
                    "ansible_ssh_pass": "password",
                    "ansible_ssh_port": 23
                }
            }
        }
    }'

This is the format that an inventory script needs to output to work with ansible, and thus here.

.. code-block:: bash

    [~]# salt-ssh --roster=ansible --roster-file /etc/salt/hosts salt.gtmanfred.com test.ping
    salt.gtmanfred.com:
            True

.. note::

    A dynamic inventory script must have the executable bit set. In the above
    example, ``chmod +x /etc/salt/hosts``.

Any of the [groups] or direct hostnames will return.  The 'all' is special, and returns everything.
�N)�get_roster_file�host�port�user�passwdZsudoZpriv)Zansible_ssh_hostZansible_ssh_portZansible_ssh_userZansible_ssh_passZansible_sudo_passZansible_ssh_private_key_file�ansiblecCstjj�d�r	tSdS)Nzansible-inventory)Fz"Install `ansible` to use inventory)�salt�utils�path�which�__virtualname__�r
r
�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/roster/ansible.py�__virtual__ysr�globcs|tjjjtt�d�td<|dkr�fdd�td�D�}n|dkr,�fdd�td�D�}n|d	kr5t��}ng}d
d�|D�S)zZ
    Return the targets from the ansible inventory_file
    Default: /etc/salt/roster
    )�	inventoryrrcsg|]
}t�|��r|�qSr
)�fnmatch��.0r��tgtr
r�
<listcomp>�s
��ztargets.<locals>.<listcomp>�all�listcsg|]}|�vr|�qSr
r
rrr
rr�sZ	nodegroupcSsi|]}|t|��qSr
)�
_get_hostvarsrr
r
r�
<dictcomp>�sztargets.<locals>.<dictcomp>)rr	r�targetsr�__opts__�__context__�_get_hosts_from_group)rZtgt_type�kwargs�hostsr
rrr�s
�
�
rcCsftd}||vr
gSdd�||�dg�D�}||�dg�D]}t|�}||vr0|�t|��q|S)NrcSsg|]}|�qSr
r
rr
r
rr�sz)_get_hosts_from_group.<locals>.<listcomp>r!�children)r�getr�extend)�grouprr!�childZ
child_infor
r
rr�s�rcCsntdd�di��|i�}t�t�di��}tD]}||vr(|�|�|t|<q||d<d|vr5||d<|S)NrZ_meta�hostvarsZroster_defaultsZminion_optsr)rr#�copy�deepcopyr�
CONVERSION�pop)rr'�ret�valuer
r
rr�s�r)r)�__doc__r(rZsalt.utils.ansiblerZsalt.utils.pathZsalt.rosterrr*rrrrrr
r
r
r�<module>s$e�