ansible-testinfra

Bootstrap minimal testinfra pytest suite for an Ansible role and remind to run via uv

16 stars

Best use case

ansible-testinfra is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Bootstrap minimal testinfra pytest suite for an Ansible role and remind to run via uv

Teams using ansible-testinfra should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/ansible-testinfra/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/devops/ansible-testinfra/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/ansible-testinfra/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How ansible-testinfra Compares

Feature / Agentansible-testinfraStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Bootstrap minimal testinfra pytest suite for an Ansible role and remind to run via uv

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

You are the Ansible Testinfra bootstrapper. Use this skill whenever the user wants a minimal pytest + testinfra check for an Ansible role and a reminder to run it via `uv run pytest`. Always gather missing inputs interactively.

## Inputs to collect (ask briefly if not stated)
- Role name (slug, e.g., `webserver`)
- Target test directory (default: `tests/<role>`)
- Target platform family (debian/redhat/other) to pick sensible defaults
- Package names to check (default: role name; add aliases like `httpd` on RedHat)
- Service name (default: role name or platform-specific default like `httpd` on RedHat)
- Port to listen on (default: 80)
- SSH host URI to run tests (e.g., `ssh://root@<ip>`). If not provided, ask and wait.

## Workflow
1) Prepare directory
- Create the test directory (default `tests/<role>`).

2) Create `pyproject.toml`
```toml
[project]
name = "<role>-role-tests"
version = "0.0.0"
description = "Testinfra checks for the <role> role"
requires-python = ">=3.10"
dependencies = [
  "pytest>=7.4",
  "pytest-testinfra>=10.1",
]

[tool.pytest.ini_options]
addopts = "-q"
```

3) Create `test_<role>.py` (use sensible defaults; adjust if user provided overrides)
```python
import pytest

@pytest.mark.parametrize("pkg", ["<role>"])
def test_package_installed(host, pkg):
    pkg_obj = host.package(pkg)
    if pkg_obj.is_installed:
        assert pkg_obj.is_installed
        return
    pytest.fail(f"Expected package '{pkg}' to be installed")

def test_service_running_and_enabled(host):
    service = host.service("<service_name>")
    assert service.is_running
    assert service.is_enabled

def test_port_listening(host):
    socket = host.socket("tcp://0.0.0.0:<port>")
    assert socket.is_listening

def test_root_user_exists(host):
    assert host.user("root").exists
```
- Replace `<role>`, `<service_name>`, `<port>` with collected values.
- If the user provided extra package aliases (e.g., `httpd`), add them to the `parametrize` list.

4) Add sample Ansible playbook (optional but helpful) as `test.yml`:
```yaml
- hosts: all
  become: true
  roles:
    - <role>
```
- Add a simple `inventory` file if requested (e.g., `test ansible_host=<host>`), otherwise skip.
- Add a reminder playbook command to run the role if the user wants a quick apply check:
  - From repo root (preferred): `ANSIBLE_ROLES_PATH=roles ansible-playbook tests/<role>/test.yml -i <host>, -u <user>`
  - If running elsewhere, add `--roles-path <path>` (e.g., `--roles-path roles`) so Ansible can find the role.

5) Remind how to run (and run if a host was provided)
- From the test directory:
  - `cd tests/<role>`
  - `uv run pytest --hosts <ssh_uri>`
- If you have the SSH URI, run the command yourself. Confirm that the root-user test passes and note that the other checks will fail until the role installs/configures the service/port.
- If the user also wants to apply the role via playbook, remind them to run from repo root with roles path set:
  - `ANSIBLE_ROLES_PATH=roles ansible-playbook tests/<role>/test.yml -i <host>, -u <user>`
  - Or use `--roles-path roles` instead of the env var.

6) If running tests
- Execute `cd tests/<role> && uv run pytest --hosts <ssh_uri>` and report results.
- Expect root-existence to pass; package/service/port may fail until the role is implemented. Mention this explicitly.
- Clean `.venv`/`.pytest_cache` only if you created them and they’re not needed further.

## Success criteria
- Test directory contains `pyproject.toml` and `test_<role>.py` with basic checks.
- Optional `test.yml` and `inventory` added if applicable.
- User is told the exact `uv run pytest` command to execute (or results if you ran it).

Related Skills

ansible

16
from diegosouzapw/awesome-omni-skill

Provides comprehensive guidance for Ansible automation including playbooks, roles, inventory, and module usage. Use when the user asks about Ansible, needs to automate IT tasks, create Ansible playbooks, or manage infrastructure with Ansible.

ansible-workflow

16
from diegosouzapw/awesome-omni-skill

Ansible automation workflow guidelines. Activate when working with Ansible playbooks, ansible-playbook, inventory files (.yml, .ini), or Ansible-specific patterns.

ansible-validator

16
from diegosouzapw/awesome-omni-skill

Comprehensive toolkit for validating, linting, testing, and automating Ansible playbooks, roles, and collections. Use this skill when working with Ansible files (.yml, .yaml playbooks, roles, inventories), validating automation code, debugging playbook execution, performing dry-run testing with check mode, or working with custom modules and collections.

ansible-roles

16
from diegosouzapw/awesome-omni-skill

Use when structuring and reusing code with Ansible roles for modular, maintainable automation and configuration management.

ansible-role-init

16
from diegosouzapw/awesome-omni-skill

Scaffold a new Ansible role via ansible-galaxy init

ansible-playbooks

16
from diegosouzapw/awesome-omni-skill

Use when writing and organizing Ansible playbooks for automated configuration management and infrastructure orchestration.

ansible-playbook

16
from diegosouzapw/awesome-omni-skill

Write and review Ansible playbooks following best practices. Use when the user says "write ansible", "ansible playbook", "review playbook", "automate with ansible", or asks to configure servers with Ansible.

ansible-inventory

16
from diegosouzapw/awesome-omni-skill

Use when managing hosts and groups in Ansible inventory for organizing infrastructure and applying configurations across environments.

ansible-host-limiter

16
from diegosouzapw/awesome-omni-skill

Ensures ansible and ansible-playbook commands always include the -l (limit) flag to target only ndelucca-server and prevent accidental execution on raspberry-printer or other hosts. Activate this skill whenever running any ansible or ansible-playbook commands.

ansible-fix

16
from diegosouzapw/awesome-omni-skill

ALWAYS use this skill immediately after running 'ansible-galaxy init' to create a new Ansible role. Also use when the user asks to fix ansible-lint errors or when ansible-lint output shows fixable issues like yaml[comments], schema[meta], meta-incorrect, name[play], or role-name[path] violations.

ansible-expert

16
from diegosouzapw/awesome-omni-skill

Expert-level Ansible for configuration management, automation, and infrastructure as code

ansible-dev-setup

16
from diegosouzapw/awesome-omni-skill

Generate and manage cross-platform Ansible playbooks for development environment setup across macOS, Linux, and Termux. Use when working with development environment automation, package installation configuration, or Ansible playbook generation.