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.

By 0xScorPionSon

8 min read

Ansible Retires pytest-ansible in December 2026: Plain pytest, tox-ansible 26.11.1, and Molecule Migration Guide

Ansible pytest-ansible end-of-life migration pipeline to ADE, tox-ansible 26.11, plain pytest, and Molecule

Executive Summary

  • Plugin retirement in December 2026: On December 3, 2026, Red Hat Partners and the Ansible DevTools team announced that the pytest-ansible plugin is reaching end of life (EOL) in December 2026 (Ansible Forum; GitHub ansible/pytest-ansible).
  • Immediate CI/CD breaking changes in tox-ansible v26.11.1: Already shipped in ansible-dev-tools (v26.11.1, released November 25, 2026), tox-ansible v26.11.1 sets up collection paths directly in test environments, drops automatic pytest-ansible installation, 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 plain pytest; integration tests move to molecule test --all (scaffolded by default starting in ansible-creator v26.12.0); and inventory-driven tests use ansible-inventory --list with @pytest.mark.parametrize (Ansible Forum).
  • Primary operational takeaway: Audit pyproject.toml, requirements-test.txt, and CI scripts for pytest_ansible imports, ansible_host/ansible_module fixtures, and --ansible-unit-inject-only flags now—or pin tox-ansible and pytest-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 --> K

Replacing 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-ansible required regular dependency churn—for example, removing pytest-sugar, termcolor, and ansible extra wrappers (#550, #552), stopping --connection flag registration to avoid plugin collisions (#551), and excluding vulnerable ansible-core 2.17.x (CVE-2026-11332 in #607) (GitHub ansible/pytest-ansible Releases). Dropping the plugin removes an entire layer of transitive dependency maintenance from ansible-dev-tools (where Red Hat plans to remove pytest-ansible as 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_scenario ran inside pytest, container startup logs, Ansible task output, and pytest assertion tracebacks were nested inside a single fixture failure. Running molecule test --all directly (or via the tox-ansible Molecule test type) surfaces native Molecule exit codes and step-level logs immediately (Ansible Forum).
  • Eliminating Matrix Waste: In earlier tox-ansible versions, Molecule-via-pytest caused duplicate environment setup overhead across Python and ansible-core matrix cells; native tox-ansible v26.11.1 separates unit, sanity, and Molecule test types cleanly (GitHub ansible/tox-ansible Releases; Ansible Forum).
  • Existing Release Pinning Escape Hatch: The pytest-ansible repository notes that existing releases (26.11.0) still install and run for teams needing extra migration runway (GitHub ansible/pytest-ansible; Ansible Forum). However, pinning tox-ansible below 26.11.1 or pinning pytest-ansible==26.11.0 is 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):

  1. Search CI and Test Requirements: Inspect pyproject.toml, setup.cfg, requirements-test.txt, tox.ini, and .github/workflows/*.yml for pytest-ansible, pytest_ansible imports, and --ansible-unit-inject-only.
  2. Audit Fixture Usage: Check whether test files actually invoke ansible_host or ansible_module, or simply reference variables with similar names (e.g., local test strings). Replace ansible_host loops with ansible-inventory --list + @pytest.mark.parametrize, and move ansible_module integration checks into Molecule scenarios or a small local test helper.
  3. Update Molecule and tox-ansible Commands: Remove pytest_ansible Molecule wrappers and invoke molecule test --all directly (matching the default starter integration test in ansible-creator v26.12.0), or configure the native Molecule test type in tox-ansible.
  4. Verify Under ADE and Drop the Dependency: Install your collection editable with Ansible Development Environment (ade install -e .), run plain pytest, confirm all unit and integration suites pass (Red Hat also shared an optional AI verification skill alongside the announcement), and remove pytest-ansible from 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 editable ansible-dev-environment virtualenvs or the community-ansible-dev-tools VS 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-test sanity: 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-ansible for collection path injection (--ansible-unit-inject-only) or molecule_scenario wrappers; tox-ansible v26.11.1 already handles collection paths natively.
  • Pin pytest-ansible==26.11.0 (and previous tox-ansible if needed) only if your suite relies heavily on custom ansible_module Python unit-test fixtures that require refactoring into Molecule scenarios—and schedule that refactor before upstream ansible-dev-tools drops 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

  1. 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)
  2. GitHub (ansible/pytest-ansible) (2026) — Repository README & Retirement Notice (Primary)
  3. GitHub (ansible/pytest-ansible) (2026) — Releases & Changelog (Primary)
  4. Ansible Development Tools Documentation (2026) — Installation & Tooling Matrix (v26.11.1) (Primary)
  5. Pythie (November 25, 2026) — ansible-dev-tools Package Telemetry (Secondary)

More on Automation

Tell us what is not working

A thirty-minute call, no deck and no obligation. You will leave with a straight answer about whether this is worth building - including if that answer is no.

Start a project

Direct line

hello@codebumble.net
Dhaka, Bangladesh  :   local timeCalls in English or Bangla