Registry / devops / ansible-core

ansible-core

JSON →
library2.21.3pypypi✓ verified 24d ago

Ansible Core is the foundational software package that provides the core language, runtime, and built-in plugins for IT automation. It enables configuring systems, deploying software, and orchestrating advanced IT tasks. As of the current version 2.20.4, ansible-core is actively maintained with minor releases occurring approximately every four weeks, and new major versions released roughly twice a year.

pip install ansible-core
INSTALL
IMPORT
SIG · ANSIBLE-CORE
A
ansible-core
devopspythonv2.21.3
Install
4.0s avg
Import
203ms
Disk
57MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.17.14 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.204s · 55.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.202s · 57MB
57MB installed
● package 57MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AnsibleModule
from ansible.module_utils.basic import AnsibleModule
Essential for writing custom Ansible modules to handle arguments, return values, and interact with the Ansible runtime.
TaskQueueManager
from ansible.executor.task_queue_manager import TaskQueueManager
Part of the internal Python API for executing tasks programmatically. Generally, `ansible-runner` is recommended for external programmatic execution.
Play
from ansible.playbook.play import Play
Used in the internal Python API to define and execute plays within a playbook programmatically.
CallbackBase
from ansible.plugins.callback import CallbackBase
Base class for creating custom callback plugins to process Ansible execution results.

This quickstart demonstrates how to programmatically execute a simple 'ping' ad-hoc command using ansible-core's internal Python API. It sets up an in-memory inventory, defines a simple play, and uses a custom callback to capture results. Note that the Ansible Python API is primarily for internal use, and `ansible-runner` is generally recommended for external programmatic integration.

import json import shutil import os import ansible.constants as C from ansible.executor.task_queue_manager import TaskQueueManager from ansible.inventory.manager import InventoryManager from ansible.parsing.dataloader import DataLoader from ansible.playbook.play import Play from ansible.plugins.callback import CallbackBase from ansible.vars.manager import VariableManager from ansible import context # NOTE: The Ansible Python API is for internal use and not officially supported for external applications. # For robust programmatic execution of playbooks and modules, consider using 'ansible-runner'. # --- Minimal example to run a simple ad-hoc command --- # Configure Ansible context (optional, but good practice) context.CLIARGS = ['ansible', 'all', '-m', 'ping', '-i', 'localhost,'] # Mimics command line args class ResultsCollectorJSONCallback(CallbackBase): def __init__(self): self.host_ok = {} self.host_failed = {} self.host_unreachable = {} def v2_runner_on_ok(self, result, **kwargs): self.host_ok[result._host.get_name()] = result._result def v2_runner_on_failed(self, result, **kwargs): self.host_failed[result._host.get_name()] = result._result def v2_runner_on_unreachable(self, result, **kwargs): self.host_unreachable[result._host.get_name()] = result._result # initialize needed objects loader = DataLoader() inv_data = 'localhost ansible_connection=local' inventory = InventoryManager(loader=loader, sources=[inv_data]) variable_manager = VariableManager(loader=loader, inventory=inventory) # instantiate our callback plugin results_callback = ResultsCollectorJSONCallback() # create play with tasks play_source = dict( name="Ansible Ad-hoc Ping", hosts='all', gather_facts='no', tasks=[ dict(action=dict(module='ping'), register='ping_result') ] ) play = Play().load(play_source, variable_manager=variable_manager, loader=loader) # run it t = TaskQueueManager( inventory=inventory, variable_manager=variable_manager, loader=loader, options=context.CLIARGS, passwords={}, stdout_callback=results_callback, ) try: status = t.run(play) finally: # cleanup after ourselves if t is not None: t.cleanup() if loader: # DataLoader may delete tmpdir on exit, ensure it's removed if exists if hasattr(loader, '_tempdir') and os.path.exists(loader._tempdir): shutil.rmtree(loader._tempdir) print("\n--- Ad-hoc Ping Results ---") print(f"OK: {json.dumps(results_callback.host_ok, indent=4)}") print(f"Failed: {json.dumps(results_callback.host_failed, indent=4)}") print(f"Unreachable: {json.dumps(results_callback.host_unreachable, indent=4)}")
ansible --version
Debug
Known issues
breakingThe `ansible-core 2.19` (and by extension `Ansible 12`) release introduced significant templating changes which may break existing playbooks and roles that relied on previously silently ignored incorrect behavior. You must validate content for compatibility.
fix
Review the official porting guides for `ansible-core 2.19` and `Ansible 12` to identify and update affected playbooks and roles.
affects: >=2.19.0
deprecatedThe `INJECT_FACTS_AS_VARS` feature was deprecated in `ansible-core 2.20`. Relying on injected facts as variables without explicit definition will eventually lead to breakage.
fix
Explicitly define facts you intend to use as variables in your playbooks or roles, rather than relying on their implicit injection. Consult the `ansible-core 2.20` porting guide.
affects: >=2.20.0
breakingSupport for Python 3.8 on control nodes was removed in `ansible-core 2.20`. Environments running older Python versions will need to be upgraded.
fix
Ensure your control node uses Python 3.9 or newer. The `requires_python` field for `ansible-core` is `>=3.12`.
affects: >=2.20.0
gotchaThe Python API of `ansible-core` is primarily intended for internal use and is not officially supported for external applications. Backward compatibility is not guaranteed, and changes may occur at any time.
fix
For robust programmatic interaction with Ansible (e.g., executing playbooks), consider using `ansible-runner` which provides a stable and supported API.
affects: All versions
breakingBehavior of `copy`, `file`, and `template` modules regarding file permissions (`mode` vs. `umask`) changed in `Ansible 2.10` and was backported to `2.8.14` and `2.9.12`. This could lead to unexpected file permissions.
fix
Explicitly set the `mode` parameter in your `copy`, `file`, and `template` tasks to ensure desired file permissions.
affects: 2.8.14+, 2.9.12+, >=2.10.0
gotchaThe `ansible-core` Python API is not thread-safe due to its reliance on forking processes.
fix
When using the `ansible-core` Python API, avoid multi-threaded contexts or implement proper process isolation (e.g., using `multiprocessing`) to prevent unexpected behavior. `ansible-runner` might offer more robust options for concurrent execution.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ansible'
Ansible is not installed in the Python environment or is installed in a different Python version.
fix
Install Ansible using pip: `pip install ansible`.
ModuleNotFoundError: No module named 'ansible.module_utils.six.moves'
Ansible is incompatible with the installed Python version, often due to using an unsupported Python release.
fix
Ensure Ansible is compatible with your Python version; consider downgrading Python or upgrading Ansible.
ModuleNotFoundError: No module named 'ansible.module_utils.common.yaml'
Ansible dependencies are missing or not properly installed.
fix
Reinstall Ansible and its dependencies: `pip install --force-reinstall ansible`.
ModuleNotFoundError: No module named 'semanage'
The 'semanage' module, required for SELinux management, is not installed.
fix
Install the 'libsemanage-python' package: `sudo yum install libsemanage-python`.
ModuleNotFoundError: No module named 'error'
Ansible is attempting to import a module named 'error', which is not found, possibly due to a misconfiguration or missing dependency.
fix
Verify Ansible installation and dependencies; consider reinstalling Ansible.
Upgrade
Version history
2.21.3latest on PyPI · released Aug 10, 2026
Audit
Dependencies
Jinja2requiredTemplating engine for playbooks and modules.
PyYAMLrequiredUsed for parsing and emitting YAML, the language for playbooks and inventory.
MarkupSaferequiredDependency of Jinja2, used for string formatting and HTML/XML escaping.
Agent activity
73 hits · last 30 days
node
66
OpenAI (training)
1
Resources
ansible-core — pip install ansible-core · libregistry