| Server IP : 198.38.94.13 / Your IP : 216.73.217.33 Web Server : Apache System : Linux d4744.dxb1.stableserver.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64 User : revivere ( 1140) PHP Version : 8.2.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/ |
Upload File : |
import logging
import os
import salt.modules.cmdmod
import salt.utils.json
import salt.utils.path
import salt.utils.stringutils
from salt.exceptions import CommandExecutionError
__virtualname__ = "ansible"
log = logging.getLogger(__name__)
def __virtual__():
if salt.utils.path.which("ansible-inventory"):
return __virtualname__
return (False, "Install `ansible` to use inventory")
def targets(inventory="/etc/ansible/hosts", yaml=False, export=False):
"""
Return the targets from the ansible inventory_file
Default: /etc/salt/roster
"""
if not os.path.isfile(inventory):
raise CommandExecutionError(f"Inventory file not found: {inventory}")
if not os.path.isabs(inventory):
raise CommandExecutionError("Path to inventory file must be an absolute path")
extra_cmd = []
if export:
extra_cmd.append("--export")
if yaml:
extra_cmd.append("--yaml")
inv = salt.modules.cmdmod.run(
"ansible-inventory -i {} --list {}".format(inventory, " ".join(extra_cmd)),
env={"ANSIBLE_DEPRECATION_WARNINGS": "0"},
reset_system_locale=False,
)
if yaml:
return salt.utils.stringutils.to_str(inv)
else:
try:
return salt.utils.json.loads(salt.utils.stringutils.to_str(inv))
except ValueError:
raise CommandExecutionError(f"Error processing the inventory: {inv}")