Automation
Ansible Retires pytest-ansible in December 2026: Plain pytest, tox-ansible 26.11.1, and Molecule Migration Guide
On December 3, 2026, Ansible announced that the pytest-ansible plugin reaches end of life in December 2026. With tox-ansible v26.11.1 dropping automatic installation and --ansible-unit-inject-only, collection maintainers need a clear migration path to ADE, plain pytest, and Molecule.
8 min read
Ansible Retires pytest-ansible in December 2026: Plain pytest, tox-ansible 26.11.1, and Molecule Migration Guide
Executive Summary
- Plugin retirement in December 2026: On December 3, 2026, Red Hat Partners and the Ansible DevTools team announced that the
pytest-ansibleplugin is reaching end of life (EOL) in December 2026 (Ansible Forum; GitHubansible/pytest-ansible). - Immediate CI/CD breaking changes in
tox-ansible v26.11.1: Already shipped inansible-dev-tools(v26.11.1, released November 25, 2026),tox-ansible v26.11.1sets up collection paths directly in test environments, drops automaticpytest-ansibleinstallation, and stops passing--ansible-unit-inject-only(Ansible Forum; Pythie). - Direct native replacements: Collection unit tests move to Ansible Development Environment (
ade install -e) with plainpytest; integration tests move tomolecule test --all(scaffolded by default starting inansible-creator v26.12.0); and inventory-driven tests useansible-inventory --listwith@pytest.mark.parametrize(Ansible Forum). - Primary operational takeaway: Audit
pyproject.toml,requirements-test.txt, and CI scripts forpytest_ansibleimports,ansible_host/ansible_modulefixtures, and--ansible-unit-inject-onlyflags now—or pintox-ansibleandpytest-ansible(26.11.0) temporarily until your collection migrates (Ansible Forum; Ansible Dev Tools Docs).
What Changed: Why pytest-ansible Is Being Retired
For over a decade, pytest-ansible bridged three distinct gaps between pytest and Ansible: injecting Ansible collection import paths for unit tests, exposing ansible_host and ansible_module fixtures for ad-hoc module execution, and wrapping Molecule scenarios inside a pytest fixture (Ansible Forum; GitHub ansible/pytest-ansible).
Over 2026, dedicated tools in the ansible-dev-tools bundle (275.5K monthly PyPI downloads, 78.4K in the last 7 days as of late November 2026) absorbed each of those responsibilities natively, making the wrapper plugin redundant (Pythie; Ansible Forum):
Legacy pytest-ansible Capability |
Replacement Mechanism (Dec 2026+) | Minimum Version / Tooling | Operational Benefit |
|---|---|---|---|
Collection unit test path injection (--ansible-unit-inject-only) |
Native collection path setup via tox-ansible + ADE (ade install -e) + plain pytest |
tox-ansible v26.11.1 / ansible-dev-environment 26.11.0 |
Eliminates custom pytest import hooks and plugin conflicts (Ansible Forum; GitHub) |
Molecule scenarios via pytest fixture (molecule_scenario) |
Direct molecule test --all or tox-ansible Molecule test type |
molecule 26.11.1 / ansible-creator v26.12.0 |
Removes double-runner indirection and flaky fixture discovery (Ansible Forum) |
Inventory & module fixtures (ansible_host, ansible_module) |
ansible-inventory --list + @pytest.mark.parametrize or repo helper / Molecule |
Plain pytest + ansible-core 2.21.4 |
Explicit test inputs without hidden plugin magic (Ansible Forum) |
Crucially, pytest-ansible had already placed Molecule-via-pytest integration on a faster deprecation track (#602) and formally documented its December 2026 retirement (#603) in its GitHub repository (GitHub ansible/pytest-ansible Releases; GitHub ansible/pytest-ansible).
The ansible-dev-tools 26.11.1 Ecosystem Baseline
According to the Ansible Development Tools Documentation, the curated ansible-dev-tools (v26.11.1) stack pairs the following verified component versions (Python 3.10+ required):
| Component | Verified Version (adt --version) |
Role in Post-pytest-ansible Stack |
|---|---|---|
ansible-core |
2.21.4 |
Core execution engine, ansible-inventory, and ansible-test runtime |
ansible-dev-environment (ADE) |
26.11.0 |
Manages editable collection installs (ade install -e) and isolated dev virtualenvs |
tox-ansible |
26.11.1 |
Builds Python/ansible-core CI matrices; sets collection paths natively without --ansible-unit-inject-only |
molecule |
26.11.1 |
Executes collection, role, and playbook integration scenarios via molecule test --all |
ansible-creator |
26.11.1 (26.12.0 adds direct Molecule starter) |
Scaffolds collection layouts and starter integration tests |
ansible-lint & ansible-navigator |
26.11.1 |
Enforces playbook/role style rules and inspects execution environments |
pytest-ansible (Retiring) |
26.11.0 |
Final transition release before December 2026 EOL and future removal from ansible-dev-tools |
flowchart TD
A[Existing Ansible Collection CI] --> B{Uses pytest-ansible?}
B -->|No| C[Safe: Plain pytest + Molecule]
B -->|Yes| D[Audit Dependencies & CI Commands]
D --> E[Check --ansible-unit-inject-only Flag]
D --> F[Check pytest_ansible Imports & Fixtures]
D --> G[Check molecule_scenario Usage]
E -->|Found| H[Upgrade to tox-ansible 26.11.1+ & Drop Flag]
F -->|Found| I[Switch to ADE + ansible-inventory --list + Parametrized pytest]
G -->|Found| J[Switch to molecule test --all or tox-ansible Molecule Type]
H --> K[Verify CI & Remove pytest-ansible From test-requirements]
I --> K
J --> KReplacing ansible_host With Plain pytest and ansible-inventory
Instead of relying on pytest-ansible fixtures to parse inventory and inject ansible_host, teams can load ansible-inventory --list directly with Python's standard subprocess and json modules and parametrize tests cleanly (Ansible Forum):
import json
import subprocess
import pytest
def load_hosts() -> list[str]:
raw = subprocess.check_output(
["ansible-inventory", "--list"],
text=True,
)
data = json.loads(raw)
return sorted(data.get("_meta", {}).get("hostvars", {}).keys())
@pytest.mark.parametrize("host", load_hosts())
def test_inventory_hosts_defined(host: str) -> None:
assert host, "Inventory host name must be non-empty"
This pattern requires zero external pytest plugins, works identically inside tox-ansible, local virtual environments, and GitHub Actions, and fails loudly if ansible-inventory encounters a syntax error. For module-level calls previously handled by the ansible_module fixture, the Ansible DevTools team recommends either a lightweight repository helper invoking ansible.runner / subprocess or moving the check into a dedicated Molecule scenario—with concrete replacement examples documented in the pytest-ansible repository README (Ansible Forum).
Reliability, Cost, and CI/CD Performance Analysis
Retiring pytest-ansible reduces hidden state, flaky test discovery, and dependency surface area in Ansible CI pipelines:
- Fewer Dependency Conflicts & Security Exposure: Over its lifecycle,
pytest-ansiblerequired regular dependency churn—for example, removingpytest-sugar,termcolor, andansibleextra wrappers (#550,#552), stopping--connectionflag registration to avoid plugin collisions (#551), and excluding vulnerableansible-core 2.17.x(CVE-2026-11332in#607) (GitHubansible/pytest-ansibleReleases). Dropping the plugin removes an entire layer of transitive dependency maintenance fromansible-dev-tools(where Red Hat plans to removepytest-ansibleas a direct dependency in a future release, with Ansible Automation Platform [AAP] DevTools package and container removal timing to be announced once confirmed) (Ansible Forum). - Cleaner Failure Diagnostics: When
molecule_scenarioran insidepytest, container startup logs, Ansible task output, and pytest assertion tracebacks were nested inside a single fixture failure. Runningmolecule test --alldirectly (or via thetox-ansibleMolecule test type) surfaces native Molecule exit codes and step-level logs immediately (Ansible Forum). - Eliminating Matrix Waste: In earlier
tox-ansibleversions, Molecule-via-pytest caused duplicate environment setup overhead across Python andansible-corematrix cells; nativetox-ansible v26.11.1separates unit, sanity, and Molecule test types cleanly (GitHubansible/tox-ansibleReleases; Ansible Forum). - Existing Release Pinning Escape Hatch: The
pytest-ansiblerepository notes that existing releases (26.11.0) still install and run for teams needing extra migration runway (GitHubansible/pytest-ansible; Ansible Forum). However, pinningtox-ansiblebelow26.11.1or pinningpytest-ansible==26.11.0is strictly a temporary bridge before upstream maintenance ceases.
Practical Implementation & Migration Checklist
Follow this four-step sequence to migrate an Ansible collection without breaking active CI matrices (Ansible Forum):
- Search CI and Test Requirements: Inspect
pyproject.toml,setup.cfg,requirements-test.txt,tox.ini, and.github/workflows/*.ymlforpytest-ansible,pytest_ansibleimports, and--ansible-unit-inject-only. - Audit Fixture Usage: Check whether test files actually invoke
ansible_hostoransible_module, or simply reference variables with similar names (e.g., local test strings). Replaceansible_hostloops withansible-inventory --list+@pytest.mark.parametrize, and moveansible_moduleintegration checks into Molecule scenarios or a small local test helper. - Update Molecule and
tox-ansibleCommands: Removepytest_ansibleMolecule wrappers and invokemolecule test --alldirectly (matching the default starter integration test inansible-creator v26.12.0), or configure the native Molecule test type intox-ansible. - Verify Under ADE and Drop the Dependency: Install your collection editable with Ansible Development Environment (
ade install -e .), run plainpytest, confirm all unit and integration suites pass (Red Hat also shared an optional AI verification skill alongside the announcement), and removepytest-ansiblefrom your test dependencies (Ansible Forum).
Choosing the Right Test Runner After Migration
With pytest-ansible retired, each layer of an Ansible collection maps cleanly to a single native runner without overlapping wrappers (Ansible Forum; Pythie):
- Plain
pytest+ ADE: Best for pure Python unit tests on custom modules, filters, lookups, and inventory-parsing helpers inside editableansible-dev-environmentvirtualenvs or thecommunity-ansible-dev-toolsVS Code devcontainer (Pythie). - Molecule (
molecule test --all): Best for idempotency, convergence, and multi-host role/playbook integration tests against containers or cloud VMs. ansible-lint&ansible-testsanity: Best for static YAML/playbook linting and upstream Ansible Galaxy / Automation Hub certification compliance.
CI/CD Configuration Diff: Legacy vs. Native Stack
# Before (Legacy pytest-ansible + tox-ansible < 26.11.1)
- name: Run collection unit tests
run: pytest --ansible-unit-inject-only tests/unit
# After (tox-ansible 26.11.1+ / ADE + plain pytest + direct Molecule)
- name: Install collection in editable dev environment
run: ade install -e .
- name: Run unit tests with plain pytest
run: pytest tests/unit
- name: Run integration scenarios directly
run: molecule test --all
When to Migrate Now vs. Pin Temporarily
- Migrate immediately if your collection only uses
pytest-ansiblefor collection path injection (--ansible-unit-inject-only) ormolecule_scenariowrappers;tox-ansible v26.11.1already handles collection paths natively. - Pin
pytest-ansible==26.11.0(and previoustox-ansibleif needed) only if your suite relies heavily on customansible_modulePython unit-test fixtures that require refactoring into Molecule scenarios—and schedule that refactor before upstreamansible-dev-toolsdrops the package completely (Ansible Forum).
Frequently Asked Questions (FAQ)
When does pytest-ansible reach end of life?
Red Hat and the Ansible DevTools team announced on December 3, 2026, that pytest-ansible reaches upstream end of life in December 2026, after which it will also be removed as a direct dependency of ansible-dev-tools (Ansible Forum).
Why did my tox-ansible CI job break with --ansible-unit-inject-only?
Starting in tox-ansible v26.11.1, tox-ansible sets up collection paths in test environments natively, stops installing pytest-ansible automatically, and no longer passes --ansible-unit-inject-only (Ansible Forum). Remove that flag from your custom test commands after verifying collection path resolution.
What replaces pytest-ansible for collection unit tests?
Use Ansible Development Environment (ade install -e) together with plain pytest (Ansible Forum; GitHub ansible/pytest-ansible).
How should I run Molecule scenarios without pytest-ansible?
Run molecule test --all directly (the default starter integration test in ansible-creator v26.12.0) or use the native Molecule test type in tox-ansible (Ansible Forum).
Can I still pin pytest-ansible temporarily if my CI breaks?
Yes. Existing PyPI releases (such as pytest-ansible==26.11.0) remain installable, and you can temporarily pin the previous tox-ansible version if CI breaks while you migrate your fixtures (Ansible Forum).
What happens to ansible-dev-tools and AAP DevTools containers?
Red Hat plans to remove pytest-ansible as a direct dependency of the upstream ansible-dev-tools bundle in a future release (Ansible Forum). For Ansible Automation Platform (AAP) users, Red Hat stated it will share exact removal timing for DevTools RPM packages and execution-environment containers once that release is confirmed (Ansible Forum).
Sources
- Ansible Community Forum (Red Hat Partners) (December 3, 2026) — Testing Ansible content with plain pytest: pytest-ansible plugin end of life in December 2026 (Primary)
- GitHub (
ansible/pytest-ansible) (2026) — Repository README & Retirement Notice (Primary) - GitHub (
ansible/pytest-ansible) (2026) — Releases & Changelog (Primary) - Ansible Development Tools Documentation (2026) — Installation & Tooling Matrix (
v26.11.1) (Primary) - Pythie (November 25, 2026) —
ansible-dev-toolsPackage Telemetry (Secondary)