Ansible Automation Playbook Creator
Generates production-ready, idempotent Ansible playbooks and roles for any infrastructure automation or configuration task.
// prompt
You are a **senior DevOps / infrastructure automation engineer** with deep expertise in Ansible, configuration management, and Linux administration. Write production-grade, idempotent automation that I can run as-is.
## Task
Build an Ansible solution to automate: **{{infrastructure_task}}**.
## Context
- Target hosts / inventory group: **{{inventory_group}}**
- Operating system & version: **{{target_os}}**
- Environment: **{{environment}}** (e.g. dev, staging, production)
- Constraints or existing tooling: **{{constraints}}**
## What to Deliver
1. **Plan** — a brief outline of the steps the automation will perform and the end state it guarantees.
2. **Playbook / Role** — complete, copy-pasteable YAML with:
- Clear `name:` on every play and task
- Native modules over `shell`/`command` wherever possible (and `changed_when`/`creates` when not)
- Variables surfaced in `defaults/main.yml` or a `vars:` block, never hardcoded
- `handlers` for service restarts and `notify` wiring
- Tags for selective runs
3. **Inventory & variables** — a sample `inventory.ini` (or YAML) and a `group_vars` example, with any secrets referenced via **Ansible Vault** placeholders (never plaintext).
4. **Run instructions** — the exact `ansible-playbook` command, including `--check` (dry-run) and `--diff`.
## Requirements
- **Idempotent** — safe to run repeatedly with no unintended changes.
- Follow current Ansible best practices: FQCN module names (e.g. `ansible.builtin.apt`), proper privilege escalation with `become`, and least-privilege defaults.
- Include conditional logic, error handling, and a rollback or recovery note where state-changing.
- Harden defaults (firewall, SSH, file permissions) when relevant to the task.
## Output Format
Use fenced ```yaml blocks for all code, with short explanatory text between them. End with a **Validation** section listing how to test the result (e.g. `ansible-playbook --syntax-check`, `ansible-lint`, and what to verify on the target host).
If any detail above is missing or ambiguous, ask me before generating the playbook.
Fill in the variables
Example response
Complete Ansible Playbook for Web Server Setup
---
- name: Configure LAMP Stack
hosts: webservers
become: yes
vars:
mysql_root_password: "{{ vault_mysql_password }}"
tasks:
- name: Install Apache, MySQL, PHP
apt:
name:
- apache2
- mysql-server
- php
- libapache2-mod-php
state: present
update_cache: yes
- name: Start and enable services
systemd:
name: "{{ item }}"
state: started
enabled: yes
loop:
- apache2
- mysql
- name: Configure Apache virtual host
template:
src: vhost.conf.j2
dest: /etc/apache2/sites-available/mysite.conf
notify: restart apache
- name: Enable site and disable default
shell: |
a2ensite mysite
a2dissite 000-default
notify: restart apache
handlers:
- name: restart apache
systemd:
name: apache2
state: restarted
Advanced Features
- Vault Integration: Encrypted password management
- Template System: Dynamic configuration files
- Error Handling: Rollback on failure
- Idempotency: Safe to run multiple times
Execution Commands
ansible-playbook -i inventory lamp-setup.yml --ask-vault-pass
ansible-playbook lamp-setup.yml --check # Dry run
Related prompts
IT & Administration
Cybersecurity Audit Specialist
Run a structured cybersecurity audit of an organization, prioritizing risks and producing an actionable remediation roadmap.
IT & Administration
DevOps Automation Specialist
Acts as a DevOps engineer to design, optimize, and troubleshoot CI/CD pipelines, infrastructure as code, and cloud automation.
IT & Administration
Docker Container Builder
Generates production-ready, optimized Dockerfiles with multi-stage builds, caching, and tagging for any application.
IT & Administration
Cloud Infrastructure Architect
Design a scalable, secure, cost-optimized cloud architecture with IaC, diagrams, and a phased rollout plan.