skills/infrastructure/ansible/generator/SKILL.md
Generates, validates, and refactors production-ready Ansible playbooks, roles, task files, and inventory configurations following current best practices. Use when the user asks to create, build, or generate Ansible automation, YAML playbooks, infrastructure as code, configuration management files, DevOps roles, or .yml files for Ansible — including requests like "create a playbook to...", "build a role for...", "generate an inventory for...", or "set up Ansible to automate...". Automatically validates all output using the devops-skills:ansible-validator skill.
npx skillsauth add pantheon-org/tekhne ansible-generatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Generate production-ready Ansible resources (playbooks, roles, task files, inventory files, project configs) following current best practices, naming conventions, and security standards. All generated resources are validated using the devops-skills:ansible-validator skill before delivery.
All capabilities follow the same validation loop: generate → invoke
devops-skills:ansible-validator→ fix errors → re-validate → present output. See Validation Workflow for full details.
Process:
references/best-practices.md and references/module-patterns.mdassets/templates/playbook/basic_playbook.yml as structural referenceExample structure:
---
# Playbook: <title>
# Description: <what it does>
# Requirements: Ansible 2.10+, <OS>
# Variables:
# - <var_name>: <description> (default: <value>)
# Usage: ansible-playbook -i inventory/<env> <playbook>.yml
- name: <Verb phrase describing the play>
hosts: <group>
become: true
gather_facts: true
vars:
app_port: 8080
pre_tasks:
- name: <Setup steps>
# ...
tasks:
- name: <Verb-first task name>
ansible.builtin.<module>:
# parameters
tags: [<tag1>, <tag2>]
post_tasks:
- name: <Verification steps>
# ...
handlers:
- name: <Handler name>
ansible.builtin.service:
name: <service>
state: reloaded
Process:
assets/templates/role/:
tasks/main.yml, handlers/main.yml, templates/, files/vars/main.yml, vars/Debian.yml, vars/RedHat.ymldefaults/main.yml, meta/main.yml, meta/argument_specs.yml (Ansible 2.11+), README.md[PLACEHOLDERS]: [ROLE_NAME], [role_name], [PLAYBOOK_DESCRIPTION], [package_name], [service_name], [default_port]nginx_port, nginx_worker_processes)include_vars for OS-specific variablesmeta/argument_specs.yml enables automatic variable validation (Ansible 2.11+).
Process:
references/module-patterns.md for module usageSee assets/templates/ for full task file examples (e.g., database backup, user management).
Process:
assets/templates/inventory/ as reference:
hosts — main inventory (INI for simple; YAML for complex hierarchies)group_vars/all.yml, group_vars/[groupname].yml, host_vars/[hostname].ymlDynamic inventory (cloud): Use provider plugins configured from references/module-patterns.md:
plugin: amazon.aws.aws_ec2plugin: azure.azcollection.azure_rmUse templates from assets/templates/project/:
ansible.cfg — forks, timeout, pathsrequirements.yml — collections and roles dependencies.ansible-lint — lint rulesWhen a user mentions a non-builtin collection (e.g., kubernetes.core, amazon.aws, community.docker):
"ansible [collection.name] [module] latest documentation examples"
mcp__context7__resolve-library-id then mcp__context7__get-library-docsInclude installation instructions in comments:
# Requirements:
# - ansible-galaxy collection install kubernetes.core:2.4.0
# or in requirements.yml:
# collections:
# - name: kubernetes.core
# version: "2.4.0"
All generated resources must follow these standards. See references/best-practices.md for full details and rationale.
Key rules at a glance:
| Standard | Correct | Incorrect |
|---|---|---|
| FQCN | ansible.builtin.copy | copy |
| Booleans | true/false | yes/no |
| RHEL packages | ansible.builtin.dnf | ansible.builtin.yum |
| Secrets | no_log: true | plain logging |
| File perms | '0644' configs, '0600' secrets | world-writable |
When validation fails due to missing collections, rewrite using builtins:
# Preferred (requires community.postgresql):
# - community.postgresql.postgresql_db: {name: mydb, state: present}
# Builtin fallback:
- name: Check if database exists
ansible.builtin.command:
cmd: psql -tAc "SELECT 1 FROM pg_database WHERE datname='mydb'"
become: true
become_user: postgres
register: db_check
changed_when: false
- name: Create database
ansible.builtin.command:
cmd: psql -c "CREATE DATABASE mydb"
become: true
become_user: postgres
when: db_check.stdout != "1"
changed_when: true
- name: Install nginx (Debian/Ubuntu)
ansible.builtin.apt:
name: nginx
state: present
when: ansible_os_family == "Debian"
- name: Install nginx (RHEL 8+)
ansible.builtin.dnf:
name: nginx
state: present
when: ansible_os_family == "RedHat"
- name: Run database migration
ansible.builtin.command: /opt/app/migrate.sh
async: 3600
poll: 0
register: migration
- name: Check migration status
ansible.builtin.async_status:
jid: "{{ migration.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 360
delay: 10
Every generated resource must be validated before presenting to the user.
devops-skills:ansible-validatorSkip validation only when: generating partial snippets, documentation examples, or when the user explicitly requests to skip.
## Generated [Resource Type]: [Name]
**Validation Status:** ✅ All checks passed
- YAML syntax: Passed
- Ansible syntax: Passed
- Ansible lint: Passed
**Summary:**
- [What was generated and key decisions]
**Usage:**
```bash
[Exact command]
```
**Prerequisites:**
- [Required collections, system requirements]
gather_facts: true by default for large inventoriesgather_facts behaviour in every play, including utility plays that never reference ansible_* variables.gather_facts: false globally in ansible.cfg and enable it per-play only when facts are actually needed (conditionals, templates using ansible_os_family, etc.).group_vars/ plaintext filesgroup_vars/ is permanently exposed in source control history, even after deletion.ansible_become_password: mypassword in group_vars/all.yml committed to the repository.ansible-vault encrypt_string) or an external secrets manager (HashiCorp Vault, AWS Secrets Manager) and reference values via lookup plugins.shell or command module when a dedicated module existsshell and command bypass idempotency guarantees, built-in error handling, and change detection that dedicated modules provide; they also resist linting and security scanning.ansible.builtin.shell: pip install requests instead of using the pip module.ansible.builtin.pip: name: requests state: present — use the purpose-built module so Ansible can detect and report actual state changes.name: fieldsansible-lint name rules.- apt: name=nginx state=present with no name: field.name:, e.g., - name: Install nginx web server.ignore_errors: true as a general exception handlerignore_errors: true silently swallows all failures and lets the playbook continue in a potentially broken state, masking errors that affect downstream tasks.ignore_errors: true on a package installation task where failure means the service cannot start.failed_when with specific conditions to define expected failure states, or use block/rescue/always for structured error handling with recovery logic.references/best-practices.md — directory structures, naming conventions, security, performance, common pitfallsreferences/module-patterns.md — module usage patterns, copy-paste examples for all common modulesassets/templates/playbook/basic_playbook.yml — playbook structure referenceassets/templates/role/* — role directory structure and variable conventionsassets/templates/inventory/* — host grouping and group_vars/host_vars patternsassets/templates/project/* — ansible.cfg, requirements.yml, .ansible-lintTemplate usage: Review structure → generate following the same pattern → replace [PLACEHOLDERS] → customize for requirements → remove inapplicable sections → validate.
tools
A skill that produces warnings but no errors.
testing
A well-formed example skill for testing the validator.
development
A skill with code blocks and imperative instructions for testing content and contamination analysis.
tools