Command Palette

Search for a command to run...

Назад к скиллам
скилл № 32231

ansible-testing

Guide for testing Ansible roles and playbooks with Molecule. Use when writing Molecule test scenarios, configuring drivers (Docker, Podman, delegated)…

БесплатноБез исполняемых скриптов
vinnie357от vinnie357★ 30 звёзд на GitHub

Установить ansible-testing в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Ansible Testing with Molecule

Activate when setting up Molecule for a role, writing test scenarios, configuring drivers, writing Testinfra assertions, or integrating Ansible tests into CI.

Why Test Ansible Code

Without automated tests:

  • Refactoring breaks things silently
  • Idempotency regressions go undetected (tasks that should be no-ops make changes on repeated runs)
  • Roles stop working on newer OS versions without anyone noticing

Molecule provides a framework to spin up a test environment, run your role against it, verify the end state, and tear it down — all automatically.

Molecule Test Phases

Molecule runs these phases in order when you execute molecule test. molecule test --help states the same list (Test (dependency, cleanup, destroy, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy)), but help text is a claim about behavior, not the behavior itself (this exact gap shipped a broken bd diff example in claude-skills-219) — the phase order below is instead cited to molecule 26.6.0's installed molecule/constants.py, whose DEFAULT["scenario"]["test_sequence"] list matches token-for-token. There is no standalone lint phase or molecule lint command in current Molecule — ansible-lint/yamllint are no longer a first-class Molecule action; run them directly (see "Linting" below) or wire them into CI alongside molecule test.

Phase What it does
dependency Install role/collection dependencies (per dependency: config)
cleanup Optional: cleanup tasks before destroy
destroy Remove any leftover test instances
syntax Syntax-check the converge playbook
create Spin up fresh test instances (containers or VMs)
prepare Optional: run a prepare playbook before converge
converge Apply your role to the test instances
idempotence Run converge again — assert zero changes
side_effect Optional: apply changes to test failure/recovery scenarios
verify Run your test assertions against live instances
cleanup Optional: cleanup tasks before destroy
destroy Tear down all test instances

Run individual phases during development:

molecule converge     # apply role (keep instance running)
molecule verify       # run assertions only
molecule login        # SSH into the test instance
molecule destroy      # tear down
molecule test         # full cycle above: dependency → cleanup → destroy → syntax → create → prepare → converge → idempotence → side_effect → verify → cleanup → destroy

Install Molecule

pip install molecule molecule-plugins[docker]   # Docker driver
pip install molecule molecule-plugins[podman]   # Podman driver
pip install pytest testinfra                    # for Testinfra verifier

Initialize a Molecule Scenario

From inside an existing role directory:

cd roles/my_role
molecule init scenario           # default scenario
molecule init scenario staging   # named scenario

molecule init scenario takes only an optional scenario-name argument — verified live against molecule 26.6.0 (molecule init scenario --help shows no other options) and by running it: --driver-name docker errors Error: No such option '--driver-name'. The driver is no longer chosen at scaffold time; it's configured (or auto-selected) separately — see "molecule.yml Structure" below.

This creates:

roles/my_role/
└── molecule/
    └── default/             # scenario name
        ├── molecule.yml     # scenario config (see below)
        ├── create.yml       # playbook that provisions test instances
        ├── converge.yml     # playbook Molecule runs against instances
        ├── destroy.yml      # playbook that tears instances down
        └── verify.yml       # assertions (if using the ansible verifier)

Verified live via molecule init scenario with molecule 26.6.0 + molecule-plugins[docker] installed — exactly these 5 files are generated, no prepare.yml (the running scenario's molecule.yml references a prepare.yml playbook path but does not create the file; add it by hand if your role needs a prepare step).

molecule.yml Structure

This schema changed from the classic driver:/platforms:/provisioner:/verifier:/lint: top-level keys documented in older Molecule guides. Verified live (molecule 26.6.0, both with and without molecule-plugins[docker] installed — same result either way) — molecule init scenario's actual default output is:

# molecule/default/molecule.yml — captured verbatim from a live `molecule init scenario` run, molecule 26.6.0
---
dependency:
  name: galaxy
  options:
    ignore-certs: false
    ignore-errors: false
    role-file: requirements.yml
    requirements-file: requirements.yml

ansible:
  cfg:
    defaults:
      host_key_checking: false
      verbosity: 1
    ssh_connection:
      pipelining: true
  env:
    ANSIBLE_FORCE_COLOR: "1"
    ANS
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • references/molecule-scenarios.md

FAQ

Что делает скилл ansible-testing?

Guide for testing Ansible roles and playbooks with Molecule. Use when writing Molecule test scenarios, configuring drivers (Docker, Podman, delegated), writing Testinfra or Ansible Verify tests, or integrating Molecule into CI pipelines.

Как установить скилл ansible-testing?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл ansible-testing запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить ansible-testing с