Ansible Generator
Trigger Phrases
Use this skill when the request is to generate or scaffold Ansible content, for example:
- "Create a playbook to deploy nginx with TLS."
- "Generate an Ansible role for PostgreSQL backups."
- "Write inventory files for prod and staging."
- "Build reusable Ansible tasks for user provisioning."
- "Initialize an Ansible project with ansible.cfg and requirements.yml."
- "Give me a quick Ansible snippet to install Docker."
Do not use this skill as the primary workflow when the request is validation/debug-only (syntax errors, lint failures, Molecule/test failures). Use ansible-validator for those cases.
Deterministic Execution Flow
Run these stages in order. Do not skip a stage unless the Validation Exceptions Matrix explicitly allows it.
Stage 0: Classify Request Mode
Determine one mode first:
| Mode |
Typical user intent |
Deliverable |
full-generation |
"create/build/generate" a full playbook/role/inventory/project file set |
Complete file(s), production-ready |
snippet-only |
"quick snippet/example" without full file context |
Focused task/play snippet |
docs-only |
explanation, pattern comparison, or conceptual guidance only |
Explanatory content, optional examples |
Stage 1: Collect Minimum Inputs
If details are missing, ask briefly. If the user does not provide them, proceed with safe defaults and state assumptions.
| Resource type |
Required inputs |
Safe defaults if missing |
| Playbook |
target hosts, privilege (become), OS family, objective |
hosts: all, become: false, OS-agnostic modules |
| Role |
role name, primary service/package, supported OS |
role name from task domain, Debian + RedHat vars |
| Tasks file |
operation scope, required vars, execution context |
standalone reusable tasks with documented vars |
| Inventory |
environments, host groups, hostnames/IPs |
production/staging groups with placeholders |
| Project config |
collections/roles dependencies, lint policy |
minimal ansible.cfg, requirements.yml, .ansible-lint |
Stage 2: Reference Extraction Checklist
Before drafting content, extract the following from local references/templates.
Required references
references/best-practices.md
- Extract: FQCN requirements, idempotency rules, naming, security expectations.
references/module-patterns.md
- Extract: correct module/parameter patterns for the exact task type.
Required templates by output type
- Playbook:
assets/templates/playbook/basic_playbook.yml
- Role:
assets/templates/role/ (including meta/argument_specs.yml and molecule/default/ for test scaffolding)
- Inventory (INI):
assets/templates/inventory/hosts
- Inventory (YAML):
assets/templates/inventory/hosts.yml
- Project config:
assets/templates/project/ansible.cfg, assets/templates/project/requirements.yml, assets/templates/project/.ansible-lint
Extraction checks
- Identify every
[PLACEHOLDER] that must be replaced.
- Decide module selection priority (
ansible.builtin.* first).
- Capture at least one OS-appropriate package pattern when OS-specific behavior is needed.
- Capture required prerequisites (collections, binaries, target assumptions).
Stage 3: Generate
Apply these generation standards:
- Use FQCN module names (
ansible.builtin.* first choice).
- Keep tasks idempotent (
state, creates/removes, changed_when when needed).
- Use descriptive verb-first task names.
- Use
true/false booleans (not yes/no).
- Add
no_log: true for sensitive values.
- Replace all placeholders before presenting output.
- Prefer
ansible.builtin.dnf for RHEL 8+/CentOS 8+ (legacy yum only for older systems).
Stage 4: Validate (Default) or Apply Exception (Fallback)
Use the matrix below to keep validation deterministic and non-blocking.
Validation Exceptions Matrix
| Scenario |
Default behavior |
Allowed fallback |
What to report |
full-generation |
Run ansible-validator after generation and after each fix pass |
If validator/tools are unavailable, run manual static checks (YAML shape, placeholder scan, FQCN/idempotency/security review) and provide exact deferred validation commands |
Explicitly list which checks ran, which were skipped, and why |
snippet-only |
Skip full validator by default; do inline sanity checks |
Run full validator only if user asks or snippet is promoted to full file |
State that validation was limited because output is snippet-only |
docs-only |
No runtime validation |
None needed |
State that no executable artifact was generated |
| Offline environment (no web/docs access) |
Continue with local references and templates |
Skip external doc lookups; prefer builtin-module implementations; provide notes for later external verification |
State offline constraint and impacted checks/lookups |
Resource Generation Guidance
Playbooks
- Use
assets/templates/playbook/basic_playbook.yml as structure.
- Include: header comments,
pre_tasks/tasks/post_tasks as needed, handlers, tags.
- Add health checks when service deployment/configuration is involved.
Roles
- Build from
assets/templates/role/ structure.
- Keep defaults in
defaults/main.yml; keep higher-priority role vars in vars/main.yml.
- Include OS-specific vars (
vars/Debian.yml, vars/RedHat.yml) when relevant.
- Add
meta/argument_specs.yml for variable validation.
- Include
molecule/default/ scaffold (from assets/templates/role/molecule/) for production-ready roles.
Task Files
- Keep scope narrow and reusable.
- Document required input variables in comments.
- Use conditionals for environment/OS-sensitive operations.
Inventory
- Build logical host groups and optional group hierarchies.
- Use variable layering intentionally:
group_vars/all.yml -> group -> host.
- Default to INI format (
hosts) for simple topologies; use YAML format (hosts.yml) when the user requests it or when the hierarchy is complex.
Project Configuration
- Provide baseline
ansible.cfg, requirements.yml, and .ansible-lint.
- Keep defaults practical and editable.
Custom Modules and Collections
When the request depends on non-builtin modules/collections:
- Identify collection + module and required version sensitivity.
- Check local
references/module-patterns.md first.
- If still unresolved and network/tools are available, query Context7:
mcp__context7__resolve-library-id
mcp__context7__query-docs
- If Context7 is unavailable, use official Ansible docs / Ansible Galaxy pages.
- If external lookup is unavailable, provide a builtin fallback approach and state the limitation.
Always include collection installation guidance when collection modules are used.
Canonical Example Flows
Flow A: Full Generation (Playbook)
User prompt: "Create a playbook to deploy nginx with TLS on Ubuntu and RHEL."
- Classify as
full-generation.
- Gather/confirm required inputs (hosts, cert paths, become, service name).
- Extract required references (
best-practices.md, module-patterns.md) and playbook template.
- Generate complete playbook with OS conditionals (
apt/dnf), handlers, validation for config templates.
- Run
ansible-validator.
- Fix issues and rerun until checks pass (or apply matrix fallback if tooling unavailable).
- Present output with validation summary, usage command, and prerequisites.
Flow B: Quick Snippet (Task Block)
User prompt: "Give me a snippet to create a user and SSH key."
- Classify as
snippet-only.
- Extract minimal module patterns for
ansible.builtin.user and ansible.builtin.authorized_key.
- Generate concise snippet with FQCN, idempotency, and variable placeholders.
- Perform inline sanity checks (YAML shape, FQCN, obvious idempotency/security).
- Present snippet and note that full validator run was skipped due to snippet-only mode.
Output Requirements
For generated executable artifacts, use this response structure:
## Generated [Resource Type]: [Name]
**Validation Status:** [Passed / Partially validated / Skipped with reason]
- YAML syntax: [status]
- Ansible syntax: [status]
- Lint: [status]
**Summary:**
- [What was generated]
- [Key implementation choices]
**Assumptions:**
- [Defaults or inferred values]
**Usage:**
```bash
[Exact command(s)]
Prerequisites:
- [Collections, binaries, environment needs]
## Done Criteria
This skill execution is complete only when all applicable items are true:
- Trigger decision is explicit (`full-generation`, `snippet-only`, or `docs-only`).
- Required references/templates were consulted for the selected artifact type.
- Generated output has no unresolved placeholders.
- Validation followed default behavior or a documented exception from the matrix.
- Any skipped checks include a concrete reason and deferred command(s).
- Final output includes summary, assumptions, usage, and prerequisites.
---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/akin-ozer) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->
1---2name: ansible-generator3description: Generate, create, or scaffold Ansible playbooks, roles, tasks, handlers, inventory, vars. Use when this capability is needed.4---56# Ansible Generator78## Trigger Phrases910Use this skill when the request is to generate or scaffold Ansible content, for example:1112- "Create a playbook to deploy nginx with TLS."13- "Generate an Ansible role for PostgreSQL backups."14- "Write inventory files for prod and staging."15- "Build reusable Ansible tasks for user provisioning."16- "Initialize an Ansible project with ansible.cfg and requirements.yml."17- "Give me a quick Ansible snippet to install Docker."1819Do not use this skill as the primary workflow when the request is validation/debug-only (syntax errors, lint failures, Molecule/test failures). Use `ansible-validator` for those cases.2021## Deterministic Execution Flow2223Run these stages in order. Do not skip a stage unless the `Validation Exceptions Matrix` explicitly allows it.2425### Stage 0: Classify Request Mode2627Determine one mode first:2829| Mode | Typical user intent | Deliverable |30| --- | --- | --- |31| `full-generation` | "create/build/generate" a full playbook/role/inventory/project file set | Complete file(s), production-ready |32| `snippet-only` | "quick snippet/example" without full file context | Focused task/play snippet |33| `docs-only` | explanation, pattern comparison, or conceptual guidance only | Explanatory content, optional examples |3435### Stage 1: Collect Minimum Inputs3637If details are missing, ask briefly. If the user does not provide them, proceed with safe defaults and state assumptions.3839| Resource type | Required inputs | Safe defaults if missing |40| --- | --- | --- |41| Playbook | target hosts, privilege (`become`), OS family, objective | `hosts: all`, `become: false`, OS-agnostic modules |42| Role | role name, primary service/package, supported OS | role name from task domain, Debian + RedHat vars |43| Tasks file | operation scope, required vars, execution context | standalone reusable tasks with documented vars |44| Inventory | environments, host groups, hostnames/IPs | `production`/`staging` groups with placeholders |45| Project config | collections/roles dependencies, lint policy | minimal `ansible.cfg`, `requirements.yml`, `.ansible-lint` |4647### Stage 2: Reference Extraction Checklist4849Before drafting content, extract the following from local references/templates.5051#### Required references5253- `references/best-practices.md`54 - Extract: FQCN requirements, idempotency rules, naming, security expectations.55- `references/module-patterns.md`56 - Extract: correct module/parameter patterns for the exact task type.5758#### Required templates by output type5960- Playbook: `assets/templates/playbook/basic_playbook.yml`61- Role: `assets/templates/role/` (including `meta/argument_specs.yml` and `molecule/default/` for test scaffolding)62- Inventory (INI): `assets/templates/inventory/hosts`63- Inventory (YAML): `assets/templates/inventory/hosts.yml`64- Project config: `assets/templates/project/ansible.cfg`, `assets/templates/project/requirements.yml`, `assets/templates/project/.ansible-lint`6566#### Extraction checks6768- Identify every `[PLACEHOLDER]` that must be replaced.69- Decide module selection priority (`ansible.builtin.*` first).70- Capture at least one OS-appropriate package pattern when OS-specific behavior is needed.71- Capture required prerequisites (collections, binaries, target assumptions).7273### Stage 3: Generate7475Apply these generation standards:76771. Use FQCN module names (`ansible.builtin.*` first choice).782. Keep tasks idempotent (`state`, `creates/removes`, `changed_when` when needed).793. Use descriptive verb-first task names.804. Use `true`/`false` booleans (not `yes`/`no`).815. Add `no_log: true` for sensitive values.826. Replace all placeholders before presenting output.837. Prefer `ansible.builtin.dnf` for RHEL 8+/CentOS 8+ (legacy `yum` only for older systems).8485### Stage 4: Validate (Default) or Apply Exception (Fallback)8687Use the matrix below to keep validation deterministic and non-blocking.8889## Validation Exceptions Matrix9091| Scenario | Default behavior | Allowed fallback | What to report |92| --- | --- | --- | --- |93| `full-generation` | Run `ansible-validator` after generation and after each fix pass | If validator/tools are unavailable, run manual static checks (YAML shape, placeholder scan, FQCN/idempotency/security review) and provide exact deferred validation commands | Explicitly list which checks ran, which were skipped, and why |94| `snippet-only` | Skip full validator by default; do inline sanity checks | Run full validator only if user asks or snippet is promoted to full file | State that validation was limited because output is snippet-only |95| `docs-only` | No runtime validation | None needed | State that no executable artifact was generated |96| Offline environment (no web/docs access) | Continue with local references and templates | Skip external doc lookups; prefer builtin-module implementations; provide notes for later external verification | State offline constraint and impacted checks/lookups |9798## Resource Generation Guidance99100### Playbooks101102- Use `assets/templates/playbook/basic_playbook.yml` as structure.103- Include: header comments, `pre_tasks`/`tasks`/`post_tasks` as needed, handlers, tags.104- Add health checks when service deployment/configuration is involved.105106### Roles107108- Build from `assets/templates/role/` structure.109- Keep defaults in `defaults/main.yml`; keep higher-priority role vars in `vars/main.yml`.110- Include OS-specific vars (`vars/Debian.yml`, `vars/RedHat.yml`) when relevant.111- Add `meta/argument_specs.yml` for variable validation.112- Include `molecule/default/` scaffold (from `assets/templates/role/molecule/`) for production-ready roles.113114### Task Files115116- Keep scope narrow and reusable.117- Document required input variables in comments.118- Use conditionals for environment/OS-sensitive operations.119120### Inventory121122- Build logical host groups and optional group hierarchies.123- Use variable layering intentionally: `group_vars/all.yml` -> group -> host.124- Default to INI format (`hosts`) for simple topologies; use YAML format (`hosts.yml`) when the user requests it or when the hierarchy is complex.125126### Project Configuration127128- Provide baseline `ansible.cfg`, `requirements.yml`, and `.ansible-lint`.129- Keep defaults practical and editable.130131## Custom Modules and Collections132133When the request depends on non-builtin modules/collections:1341351. Identify collection + module and required version sensitivity.1362. Check local `references/module-patterns.md` first.1373. If still unresolved and network/tools are available, query Context7:138 - `mcp__context7__resolve-library-id`139 - `mcp__context7__query-docs`1404. If Context7 is unavailable, use official Ansible docs / Ansible Galaxy pages.1415. If external lookup is unavailable, provide a builtin fallback approach and state the limitation.142143Always include collection installation guidance when collection modules are used.144145## Canonical Example Flows146147### Flow A: Full Generation (Playbook)148149User prompt: "Create a playbook to deploy nginx with TLS on Ubuntu and RHEL."1501511. Classify as `full-generation`.1522. Gather/confirm required inputs (hosts, cert paths, become, service name).1533. Extract required references (`best-practices.md`, `module-patterns.md`) and playbook template.1544. Generate complete playbook with OS conditionals (`apt`/`dnf`), handlers, validation for config templates.1555. Run `ansible-validator`.1566. Fix issues and rerun until checks pass (or apply matrix fallback if tooling unavailable).1577. Present output with validation summary, usage command, and prerequisites.158159### Flow B: Quick Snippet (Task Block)160161User prompt: "Give me a snippet to create a user and SSH key."1621631. Classify as `snippet-only`.1642. Extract minimal module patterns for `ansible.builtin.user` and `ansible.builtin.authorized_key`.1653. Generate concise snippet with FQCN, idempotency, and variable placeholders.1664. Perform inline sanity checks (YAML shape, FQCN, obvious idempotency/security).1675. Present snippet and note that full validator run was skipped due to snippet-only mode.168169## Output Requirements170171For generated executable artifacts, use this response structure:172173```markdown174## Generated [Resource Type]: [Name]175176**Validation Status:** [Passed / Partially validated / Skipped with reason]177- YAML syntax: [status]178- Ansible syntax: [status]179- Lint: [status]180181**Summary:**182- [What was generated]183- [Key implementation choices]184185**Assumptions:**186- [Defaults or inferred values]187188**Usage:**189```bash190[Exact command(s)]191```192193**Prerequisites:**194- [Collections, binaries, environment needs]195```196197## Done Criteria198199This skill execution is complete only when all applicable items are true:200201- Trigger decision is explicit (`full-generation`, `snippet-only`, or `docs-only`).202- Required references/templates were consulted for the selected artifact type.203- Generated output has no unresolved placeholders.204- Validation followed default behavior or a documented exception from the matrix.205- Any skipped checks include a concrete reason and deferred command(s).206- Final output includes summary, assumptions, usage, and prerequisites.207208---209> Converted and distributed by [TomeVault](https://tomevault.io/claim/akin-ozer) — claim your Tome and manage your conversions.210<!-- tomevault:4.0:skill_md:2026-04-11 -->