Ansible Playbook Generator Prompt
Generate idempotent Ansible playbooks with proper handlers, tags, and check-mode support.
- Target user
- Sysadmins and DevOps engineers writing Ansible automation
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior Ansible engineer who writes playbooks deployed across thousands of production hosts. Generate an Ansible playbook for the task I describe. Requirements: 1. **Idempotency first.** Every task should be safe to run repeatedly. Use proper modules (apt, dnf, copy, template, service, lineinfile) — avoid `command:` and `shell:` unless absolutely necessary, and when used, gate with `creates:`, `removes:`, or `changed_when:`. 2. **Handlers for restarts.** Use `notify:` with handlers, not inline restart tasks. 3. **Tags on every task** for selective runs. 4. **Check-mode safe.** All tasks should work under `--check`. 5. **Variables at the top** with sane defaults. Document each variable in a comment. 6. **No hardcoded secrets** — use `ansible-vault`-friendly variable names. 7. **Conditional based on OS family** if the task differs across Debian/RHEL. 8. After the playbook, list what could break, and how to test with `--check` and `--diff`. Task to automate: [DESCRIBE] Target OS(es): [Ubuntu 22.04 / RHEL 9 / Rocky 9 / mixed] Ansible version: [2.16+]
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
Most AI-generated Ansible is bad in the same way: lots of shell: and command:, no handlers, no tags, no check-mode support. This prompt explicitly forbids those failure modes.
How to use it
- Describe the outcome, not the steps. “Install and configure nginx with a hardened TLS config” beats “run apt-get install nginx then edit nginx.conf.”
- State your target OS upfront. Cross-distro playbooks need different modules (apt vs dnf).
- Always test the result with
ansible-playbook --check --diffbefore running for real.
Quick validation checklist
- Does every task have a
name:? - Are restarts wired through handlers?
- Does
ansible-playbook --checkcomplete cleanly? - Are there any
command:orshell:tasks withoutchanged_when:orcreates:?
Related prompts
-
Bash Script Code Review Prompt
Get a senior-engineer review of any Bash script — safety, idempotency, error handling, portability.
-
Linux Server Troubleshooting Prompt
Help diagnose CPU, memory, disk, network, and service issues on Ubuntu or RHEL servers from raw command output.
-
Bash Multi-Repo Git Bulk Command Runner Prompt
Build a Bash script that runs the same git or shell command across many local repositories with per-repo isolation, dirty-tree guards, and an aggregated pass/fail summary
-
Bash Safe In-Place sed Edit Wrapper Prompt
Build a Bash wrapper around sed -i that backs up, validates, and atomically applies in-place edits so a bad expression can never corrupt or truncate config files
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.