Ansible (Base)
raw JSON → 2.10.17 verified Mon Apr 27 auth: no python deprecated
The foundational library for Ansible automation, containing the core execution engine, modules, and plugins. Version 2.10.17 is the final release of ansible-base before it was renamed to ansible-core. Requires Python >=2.7 and <3.5 or >=3.5.
pip install ansible-base==2.10.17 Common errors
error ModuleNotFoundError: No module named 'ansible_base' ↓
cause Users try to import ansible_base as a Python module.
fix
Do not import ansible_base. Instead, use from ansible import ... or install ansible-core and use its modules.
error pip install ansible-base fails with 'Could not find a version that satisfies the requirement ansible-base' ↓
cause The package is no longer maintained and was removed from PyPI or only available for older Python versions.
fix
Use 'pip install ansible-core' instead, or specify exact version like 'ansible-base==2.10.17'.
error ImportError: cannot import name 'AnsibleModule' from 'ansible.module_utils.basic' (unknown location) ↓
cause Trying to use AnsibleModule outside of module context or using incompatible version.
fix
Ensure you are running inside an Ansible module; for API usage, use ansible-core's task executor.
Warnings
breaking ansible-base was renamed to ansible-core starting from version 2.11. Any code importing from ansible-base or using pip install ansible-base will stop receiving updates. ↓
fix Use pip install ansible-core and update imports to ansible-core's structure (which is similar but may have moved modules).
gotcha Python compatibility: ansible-base 2.10 requires Python >=2.7 and <3.5, or >=3.5. Python 3.5 is EOL and 2.7 is EOL. Upgrading is strongly recommended. ↓
fix Update to Python >=3.8 and use ansible-core or ansible package.
deprecated The package ansible-base is deprecated; use ansible-core or ansible. ↓
fix Replace dependency with ansible-core for the runtime or ansible for the full distribution.
Imports
- ansible_base wrong
import ansible_basecorrectNo import; use ansible-core or ansible package - AnsibleModule wrong
from ansible.module_utils.ansible_base import AnsibleModulecorrectfrom ansible.module_utils.basic import AnsibleModule
Quickstart
import ansible.constants as C
import ansible.inventory.manager
from ansible.parsing.dataloader import DataLoader
from ansible.vars.manager import VariableManager
from ansible.inventory.host import Host
from ansible.playbook.play import Play
from ansible.executor.task_queue_manager import TaskQueueManager
from ansible.plugins.callback import CallbackBase
# Example: run a simple ping module
options = {'connection': 'local', 'module_path': '', 'forks': 100, 'become': None, 'become_method': None, 'become_user': None, 'check': False, 'diff': False}
loader = DataLoader()
inventory = ansible.inventory.manager.InventoryManager(loader=loader, sources='localhost,')
variable_manager = VariableManager(loader=loader, inventory=inventory)
play_source = dict(
name = 'Ansible Play',
hosts = 'localhost',
gather_facts = 'no',
tasks = [
dict(action=dict(module='ping', args='')),
]
)
play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
class ResultCallback(CallbackBase):
def __init__(self, *args, **kwargs):
super(ResultCallback, self).__init__(*args, **kwargs)
self.results = []
def v2_runner_on_ok(self, result, **kwargs):
self.results.append({'ok': result._result})
tqm = TaskQueueManager(
inventory=inventory,
variable_manager=variable_manager,
loader=loader,
options=options,
passwords=None,
stdout_callback=ResultCallback(),
)
tqm.run(play)
tqm.cleanup()