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.
Comprehensive toolkit for validating, linting, and testing Ansible playbooks, roles, and collections. This skill provides automated workflows for ensuring Ansible code quality, syntax validation, dry-run testing with check mode and molecule, and intelligent documentation lookup for custom modules and collections with version awareness.
Default behavior: When validating any Ansible role with a molecule/ directory, attempt Molecule automatically using bash scripts/test_role.sh <role-path>. If Molecule cannot run due to environment/runtime limits, mark Molecule as BLOCKED, report why, and continue all non-Molecule validation steps.
Use this skill when the request is about validating or debugging existing Ansible code, not generating new code.
Common trigger phrases:
Apply this skill when encountering any of these scenarios:
.yml, .yaml playbooks, roles, inventories, vars)ansible-playbook --checkRun preflight before validation to avoid dead ends:
bash scripts/setup_tools.sh
Command path assumption: run commands from this skill root (devops-skills-plugin/skills/ansible-validator) or use absolute paths.
Preflight requirements:
ansible, ansible-playbook, ansible-lint (plus yamllint recommended)molecule plus an available runtime (docker or podman)checkov (wrapper can bootstrap if missing)Deterministic fallback rules:
BLOCKED, and continue.BLOCKED, and continue remaining stages.Use wrappers by default for consistent behavior and fallback handling.
| Validation scenario | Default command | Use direct command when | Fallback if command cannot run |
|---|---|---|---|
| Playbook syntax/lint | bash scripts/validate_playbook.sh <playbook.yml> | User asks for a single focused check only (ansible-playbook --syntax-check, ansible-lint, or yamllint) | Run any available direct checks and report skipped checks as BLOCKED |
| Role structural validation | bash scripts/validate_role.sh <role-dir> | User asks only for specific sub-checks (for example, structure only) | Run structure/YAML checks that are possible and report missing stages |
| Role Molecule execution | bash scripts/test_role.sh <role-dir> [scenario] | User explicitly asks for manual stage-by-stage Molecule commands | Mark Molecule BLOCKED with reason and continue non-Molecule role checks |
| Security scanning | bash scripts/validate_playbook_security.sh <path> or bash scripts/validate_role_security.sh <path> plus bash scripts/scan_secrets.sh <path> | User requests raw Checkov output formatting or custom flags | Run whichever scanner is available; if one is missing, run the other and report coverage gap |
| Module/collection discovery | bash scripts/extract_ansible_info_wrapper.sh <path> | Python environment is already known-good and user wants direct parser output | If extraction fails, manually inspect requirements.yml/galaxy.yml and continue with best-effort lookup |
Follow this deterministic workflow and never stop at a missing dependency:
0. Preflight
├─> Run: bash scripts/setup_tools.sh
├─> Record tool/runtime readiness
└─> Continue even when optional tools are missing
1. Identify scope
├─> Single playbook validation
├─> Role validation
├─> Collection validation
└─> Multi-playbook/inventory validation
2. Syntax Validation
├─> Run ansible-playbook --syntax-check
├─> Run yamllint for YAML syntax
└─> Report as PASS/FAIL/BLOCKED
3. Lint and Best Practices
├─> Run ansible-lint (comprehensive linting)
├─> Check for deprecated modules (see references/module_alternatives.md)
├─> **DETECT NON-FQCN MODULE USAGE** (apt vs ansible.builtin.apt)
│ └─> Run bash scripts/check_fqcn.sh to identify short module names
│ └─> Recommend FQCN alternatives from references/module_alternatives.md
├─> Verify role structure
└─> Report linting issues
4. Dry-Run Testing (check mode)
├─> Run ansible-playbook --check (if inventory available)
├─> Analyze what would change
└─> Report potential issues
5. Molecule Testing (for roles with molecule/) - AUTOMATIC ATTEMPT
├─> Check if molecule/ directory exists in role
├─> If present, run: bash scripts/test_role.sh <role-path> [scenario]
├─> If script exits 2, mark Molecule as BLOCKED (environment/runtime issue)
├─> If script exits 1, mark Molecule as FAIL (role/test issue)
└─> Continue remaining validation regardless of Molecule outcome
6. Custom Module/Collection Analysis (if detected)
├─> Extract module/collection information
├─> Identify versions
├─> Lookup documentation (Context7 first, then web.search_query fallback)
└─> Provide version-specific guidance
7. Security and Best Practices Review - DUAL SCANNING DEFAULT
├─> Run bash scripts/validate_playbook_security.sh or validate_role_security.sh (Checkov)
├─> Run bash scripts/scan_secrets.sh for hardcoded secret detection
│ └─> This catches secrets Checkov may miss (passwords, API keys, tokens)
├─> If one scanner is unavailable, run the other and report reduced coverage
├─> Validate privilege escalation
├─> Review file permissions
└─> Identify common anti-patterns
8. Reference Routing
├─> Map each error/warning class to the matching reference file
├─> Extract concrete remediation from references (not file-name-only mention)
└─> Include source section + fix guidance in final report
9. Final Report (required format)
├─> Summary counts: PASS / FAIL / BLOCKED / SKIPPED
├─> Findings grouped by severity
├─> Tool/runtime blockers with exact command that failed
└─> Next actions to reach full validation coverage
Status contract: BLOCKED means validation could not run due to environment/runtime constraints; FAIL means the Ansible code or tests failed.
When issues are detected, consult the mapped reference and include a specific remediation excerpt in the report.
| Error class | Typical detector | Required reference | Required action |
|---|---|---|---|
| YAML parse/format errors | yamllint, ansible-playbook --syntax-check | references/common_errors.md (Syntax Errors) | Quote the matching syntax fix pattern and apply corrected YAML structure |
| Module/action resolution errors | ansible-playbook, ansible-lint | references/common_errors.md (Module/Collection Errors) | Provide install/version fix commands (ansible-galaxy collection install ...) |
| Deprecated or non-FQCN module usage | ansible-lint, bash scripts/check_fqcn.sh | references/module_alternatives.md | Provide exact FQCN/module replacement per finding |
| Template/variable errors | ansible-playbook, check mode | references/common_errors.md (Template/Variable Errors), references/best_practices.md (Variable Management) | Recommend default(), required(), or type conversion fixes |
| Connection/inventory/privilege errors | ansible-playbook --check, runtime output | references/common_errors.md (Connection, Inventory, Privilege sections) | Provide corrected inventory/auth/become configuration |
| Security policy failures (CKV_*) | validate_*_security.sh / Checkov | references/security_checklist.md | Map failed policy to a secure task rewrite |
| Hardcoded secrets | bash scripts/scan_secrets.sh | references/security_checklist.md (Secrets Management) | Replace with Vault/env/external secret manager approach |
| Role structure/idempotency warnings | validate_role.sh, Molecule idempotence | references/best_practices.md | Provide role layout or idempotency remediation steps |
External documentation lookup trigger:
Purpose: Ensure YAML files are syntactically correct before Ansible parsing.
Tools:
yamllint - YAML linter for syntax and formattingansible-playbook --syntax-check - Ansible-specific syntax validationWorkflow:
# Check YAML syntax with yamllint
yamllint playbook.yml
# Or for entire directory
yamllint -c .yamllint .
# Check Ansible playbook syntax
ansible-playbook playbook.yml --syntax-check
Common Issues Detected:
Best Practices:
.yamllintPurpose: Enforce Ansible best practices and catch common errors.
Workflow:
# Lint a single playbook
ansible-lint playbook.yml
# Lint all playbooks in directory
ansible-lint .
# Lint with specific rules
ansible-lint -t yaml,syntax playbook.yml
# Skip specific rules
ansible-lint -x yaml[line-length] playbook.yml
# Output parseable format
ansible-lint -f pep8 playbook.yml
# Show rule details
ansible-lint -L
Common Issues Detected:
command vs shellbecome directivesSeverity Levels:
Auto-fix approach:
--fix for auto-fixable issuesPurpose: Identify security vulnerabilities and compliance violations in Ansible code using Checkov, a static code analysis tool for infrastructure-as-code.
What Checkov Provides Beyond ansible-lint:
While ansible-lint focuses on code quality and best practices, Checkov specifically targets security policies and compliance:
Workflow:
# Scan playbook for security issues
bash scripts/validate_playbook_security.sh playbook.yml
# Scan entire directory
bash scripts/validate_playbook_security.sh /path/to/playbooks/
# Scan role for security issues
bash scripts/validate_role_security.sh roles/webserver/
# Direct checkov usage
checkov -d . --framework ansible
# Scan with specific output format
checkov -d . --framework ansible --output json
# Scan and skip specific checks
checkov -d . --framework ansible --skip-check CKV_ANSIBLE_1
Common Security Issues Detected:
Certificate Validation:
HTTPS Enforcement:
Package Security:
Error Handling:
Cloud Security (when managing cloud resources):
Example Violation:
# BAD - Disables certificate validation
- name: Download file
get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
validate_certs: false # Security issue!
# GOOD - Certificate validation enabled
- name: Download file
get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
validate_certs: true # Or omit (true by default)
Integration with Validation Workflow:
Checkov complements ansible-lint:
Best Practice: Run both tools for comprehensive validation:
# Complete validation workflow
bash scripts/validate_playbook.sh playbook.yml # Syntax + Lint
bash scripts/validate_playbook_security.sh playbook.yml # Security
Output Format:
Checkov provides clear security scan results:
Security Scan Results:
Passed: 15 checks
Failed: 2 checks
Skipped: 0 checks
Failed Checks:
Check: CKV_ANSIBLE_2 - "Ensure that certificate validation isn't disabled with get_url"
FAILED for resource: tasks/main.yml:download_file
File: /roles/webserver/tasks/main.yml:10-15
Remediation Resources:
references/security_checklist.mdreferences/best_practices.mdInstallation:
Checkov is automatically installed in a temporary environment if not available system-wide. For permanent installation:
pip3 install checkov
When to Use:
Purpose: Validate playbook syntax without executing tasks.
Workflow:
# Basic syntax check
ansible-playbook playbook.yml --syntax-check
# Syntax check with inventory
ansible-playbook -i inventory playbook.yml --syntax-check
# Syntax check with extra vars
ansible-playbook playbook.yml --syntax-check -e @vars.yml
# Check all playbooks
for file in *.yml; do
ansible-playbook "$file" --syntax-check
done
Validation Checks:
Error Handling:
Purpose: Preview changes that would be made without actually applying them.
Workflow:
# Run in check mode (dry-run)
ansible-playbook -i inventory playbook.yml --check
# Check mode with diff
ansible-playbook -i inventory playbook.yml --check --diff
# Check mode with verbose output
ansible-playbook -i inventory playbook.yml --check -v
# Check mode for specific hosts
ansible-playbook -i inventory playbook.yml --check --limit webservers
# Check mode with tags
ansible-playbook -i inventory playbook.yml --check --tags deploy
# Step through tasks
ansible-playbook -i inventory playbook.yml --check --step
Check Mode Analysis:
When reviewing check mode output, focus on:
Task Changes:
ok: No changes neededchanged: Would make changesfailed: Would fail (check for check_mode support)skipped: Conditional skipDiff Output:
Handlers:
Failed Tasks:
check_mode: no overrideLimitations:
Safety Considerations:
Purpose: Test Ansible roles in isolated environments with multiple scenarios.
Automatic attempt policy: When validating any Ansible role with a molecule/ directory, automatically attempt Molecule tests using bash scripts/test_role.sh <role-path> [scenario].
When to Use:
Workflow:
# Initialize molecule for a role
cd roles/myrole
molecule init scenario --driver-name docker
# List scenarios
molecule list
# Run full test sequence
molecule test
# Individual test stages
molecule create # Create test instances
molecule converge # Run Ansible against instances
molecule verify # Run verification tests
molecule destroy # Destroy test instances
# Test with specific scenario
molecule test -s alternative
# Debug mode
molecule --debug test
# Keep instances for debugging
molecule converge
molecule login # SSH into test instance
Test Sequence:
dependency - Install role dependencieslint - Run yamllint and ansible-lintcleanup - Clean up before testingdestroy - Destroy existing instancessyntax - Run syntax checkcreate - Create test instancesprepare - Prepare instances (install requirements)converge - Run the roleidempotence - Run again, verify no changesside_effect - Optional side effect playbookverify - Run verification tests (Testinfra, etc.)cleanup - Final cleanupdestroy - Destroy test instancesMolecule Configuration:
Check molecule/default/molecule.yml:
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: ubuntu:22.04
provisioner:
name: ansible
verifier:
name: ansible
Verification Tests:
Molecule supports multiple verifiers:
Example Ansible verifier (molecule/default/verify.yml):
---
- name: Verify
hosts: all
tasks:
- name: Check service is running
service:
name: nginx
state: started
check_mode: true
register: result
failed_when: result.changed
Common Molecule Errors:
Molecule Skip/Fallback Policy (Required):
molecule/ does not exist: mark Molecule as SKIPPED and continue.test_role.sh exits 2: mark Molecule as BLOCKED (missing/unavailable runtime dependency) and continue.test_role.sh exits 1: mark Molecule as FAIL (role/test issue) and continue.Use this reporting language for blocked Molecule runs:
Molecule Status: BLOCKED
Reason: <missing dependency/runtime and failing command>
Fallback Applied: Completed syntax, lint, check-mode, and security validation without Molecule runtime tests.
Next Action: <install/start dependency>; rerun `bash scripts/test_role.sh <role-path> [scenario]`
Purpose: Automatically discover and retrieve version-specific documentation for custom modules and collections using web search and Context7 MCP.
When to Trigger:
Detection Workflow:
Extract Module Information:
scripts/extract_ansible_info_wrapper.sh to parse playbooks and rolesrequirements.ymlExtract Collection Information:
community.general, ansible.posix)requirements.yml or galaxy.ymlDocumentation Lookup Strategy:
Use this deterministic lookup order:
mcp__context7__resolve-library-idmcp__context7__query-docsweb.search_query with versioned queriesREADME, module docs, role docs) firstSearch Query Templates:
# For custom modules
"[module-name] ansible module version [version] documentation"
"[module-name] ansible [module-type] example"
"ansible [collection-name].[module-name] parameters"
# For custom collections
"ansible collection [collection-name] version [version]"
"[collection-namespace].[collection-name] ansible documentation"
"ansible galaxy [collection-name] modules"
# For specific errors
"ansible [module-name] error: [error-message]"
"ansible [collection-name] module failed"
Example Workflow:
User working with: community.docker.docker_container version 3.0.0
1. Extract module info from playbook:
tasks:
- name: Start container
community.docker.docker_container:
name: myapp
image: nginx:latest
2. Detect collection: community.docker
3. Search for documentation:
- Try Context7: mcp__context7__resolve-library-id("ansible community.docker")
- Fallback to web.search_query("ansible community.docker col
<!-- Content truncated for initial SEO render. Open the source file tab for the full file. -->
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer