Consistent Ansible Python API and CLI with container and process isolation runtime capabilities
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Discover, document, and manage Ansible plugins and roles programmatically. Provides access to plugin documentation, role specifications, inventory operations, and Ansible configuration management through a consistent programmatic interface.
Retrieve documentation for Ansible plugins including modules, lookup plugins, filter plugins, and other plugin types.
def get_plugin_docs(
plugin_names: list,
plugin_type: str = None,
response_format: str = None,
snippet: bool = False,
playbook_dir: str = None,
module_path: str = None,
private_data_dir: str = None,
artifact_dir: str = None,
ident: str = None,
rotate_artifacts: int = 0,
timeout: int = None,
process_isolation: bool = False,
process_isolation_executable: str = None,
container_image: str = None,
envvars: dict = None,
**kwargs
) -> RunnerParameters:
Usage examples:
import ansible_runner
# Get documentation for specific modules
result = ansible_runner.get_plugin_docs(
plugin_names=['copy', 'template', 'service'],
plugin_type='module',
response_format='json'
)
# Get brief snippets for quick reference
result = ansible_runner.get_plugin_docs(
plugin_names=['file', 'lineinfile'],
plugin_type='module',
snippet=True,
response_format='text'
)
# Get lookup plugin documentation
result = ansible_runner.get_plugin_docs(
plugin_names=['env', 'file', 'template'],
plugin_type='lookup',
response_format='yaml'
)def get_plugin_docs_async(
plugin_names: list,
plugin_type: str = None,
response_format: str = None,
snippet: bool = False,
playbook_dir: str = None,
module_path: str = None,
private_data_dir: str = None,
artifact_dir: str = None,
ident: str = None,
rotate_artifacts: int = 0,
timeout: int = None,
process_isolation: bool = False,
process_isolation_executable: str = None,
container_image: str = None,
envvars: dict = None,
**kwargs
) -> RunnerUsage example:
# Async plugin documentation retrieval
runner = ansible_runner.get_plugin_docs_async(
plugin_names=['yum', 'apt', 'package'],
plugin_type='module',
response_format='json'
)
# Wait for completion
while runner.status in ['pending', 'running']:
time.sleep(0.5)
if runner.status == 'successful':
print("Plugin documentation retrieved successfully")List available Ansible plugins by type or search criteria.
def get_plugin_list(
list_files: str = None,
response_format: str = None,
plugin_type: str = None,
playbook_dir: str = None,
module_path: str = None,
private_data_dir: str = None,
artifact_dir: str = None,
ident: str = None,
rotate_artifacts: int = 0,
timeout: int = None,
process_isolation: bool = False,
process_isolation_executable: str = None,
container_image: str = None,
envvars: dict = None,
**kwargs
) -> RunnerParameters:
Usage examples:
# List all available modules
result = ansible_runner.get_plugin_list(
plugin_type='module',
response_format='json'
)
# List lookup plugins
result = ansible_runner.get_plugin_list(
plugin_type='lookup',
response_format='text'
)
# List all plugin types
result = ansible_runner.get_plugin_list(
response_format='yaml'
)List available Ansible roles from collections or local directories.
def get_role_list(
collection: str = None,
playbook_dir: str = None,
private_data_dir: str = None,
artifact_dir: str = None,
ident: str = None,
rotate_artifacts: int = 0,
timeout: int = None,
process_isolation: bool = False,
process_isolation_executable: str = None,
container_image: str = None,
envvars: dict = None,
**kwargs
) -> RunnerParameters:
Usage examples:
# List all available roles
result = ansible_runner.get_role_list()
# List roles from specific collection
result = ansible_runner.get_role_list(
collection='community.general'
)
# List roles from specific directory
result = ansible_runner.get_role_list(
playbook_dir='/path/to/ansible/project'
)Get detailed argument specifications for Ansible roles.
def get_role_argspec(
role: str,
collection: str = None,
playbook_dir: str = None,
private_data_dir: str = None,
artifact_dir: str = None,
ident: str = None,
rotate_artifacts: int = 0,
timeout: int = None,
process_isolation: bool = False,
process_isolation_executable: str = None,
container_image: str = None,
envvars: dict = None,
**kwargs
) -> RunnerParameters:
Usage examples:
# Get argument spec for a role
result = ansible_runner.get_role_argspec(
role='nginx'
)
# Get argument spec for role in collection
result = ansible_runner.get_role_argspec(
role='apache',
collection='community.general'
)
# Get argument spec with custom playbook directory
result = ansible_runner.get_role_argspec(
role='custom_app',
playbook_dir='/path/to/roles'
)Execute ansible-inventory commands for inventory management and inspection.
def get_inventory(
action: str,
inventories: list,
response_format: str = None,
host: str = None,
playbook_dir: str = None,
private_data_dir: str = None,
artifact_dir: str = None,
ident: str = None,
rotate_artifacts: int = 0,
timeout: int = None,
process_isolation: bool = False,
process_isolation_executable: str = None,
container_image: str = None,
envvars: dict = None,
**kwargs
) -> RunnerParameters:
Usage examples:
# List entire inventory
result = ansible_runner.get_inventory(
action='list',
inventories=['inventory/hosts'],
response_format='json'
)
# Get information for specific host
result = ansible_runner.get_inventory(
action='host',
inventories=['inventory/hosts'],
host='web01',
response_format='json'
)
# Generate inventory graph
result = ansible_runner.get_inventory(
action='graph',
inventories=['inventory/hosts', 'inventory/groups'],
response_format='text'
)Get and manage Ansible configuration settings.
def get_ansible_config(
action: str,
config_file: str = None,
only_changed: bool = None,
private_data_dir: str = None,
artifact_dir: str = None,
ident: str = None,
rotate_artifacts: int = 0,
timeout: int = None,
process_isolation: bool = False,
process_isolation_executable: str = None,
container_image: str = None,
envvars: dict = None,
**kwargs
) -> RunnerParameters:
Usage examples:
# View current configuration
result = ansible_runner.get_ansible_config(
action='view'
)
# Dump all configuration settings
result = ansible_runner.get_ansible_config(
action='dump'
)
# List all available configuration options
result = ansible_runner.get_ansible_config(
action='list'
)
# Show only changed settings
result = ansible_runner.get_ansible_config(
action='dump',
only_changed=True
)import ansible_runner
# 1. List available modules
modules_result = ansible_runner.get_plugin_list(
plugin_type='module',
response_format='json'
)
# 2. Get documentation for specific modules
if modules_result.status == 'successful':
docs_result = ansible_runner.get_plugin_docs(
plugin_names=['file', 'copy', 'template'],
plugin_type='module',
response_format='json'
)
# 3. Get brief snippets for quick reference
snippets_result = ansible_runner.get_plugin_docs(
plugin_names=['file', 'copy'],
plugin_type='module',
snippet=True,
response_format='text'
)# 1. List all available roles
roles_result = ansible_runner.get_role_list()
# 2. Get argument specification for specific role
if roles_result.status == 'successful':
argspec_result = ansible_runner.get_role_argspec(
role='nginx',
collection='community.general'
)
# 3. Validate role arguments
if argspec_result.status == 'successful':
print("Role arguments validated successfully")# 1. Get complete inventory listing
inventory_result = ansible_runner.get_inventory(
action='list',
inventories=['production/hosts'],
response_format='json'
)
# 2. Analyze specific hosts
for host in ['web01', 'db01', 'app01']:
host_result = ansible_runner.get_inventory(
action='host',
inventories=['production/hosts'],
host=host,
response_format='json'
)
if host_result.status == 'successful':
print(f"Host {host} configuration retrieved")
# 3. Generate inventory visualization
graph_result = ansible_runner.get_inventory(
action='graph',
inventories=['production/hosts'],
response_format='text'
)Install with Tessl CLI
npx tessl i tessl/pypi-ansible-runner