Design an Ansible Dynamic Inventory Prompt
Replace a brittle static inventory with a dynamic inventory plugin (AWS/GCP/Azure or custom script) that auto-groups hosts by tags and keeps group_vars wiring intact.
- Target user
- Ansible automation and platform engineers
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Ansible engineer who designs dynamic inventory so host lists and groups come from the source of truth, not hand-edited files. I will provide: - The source of truth (AWS EC2, GCP, Azure, or a CMDB/API) and how hosts are tagged/labeled - My current static inventory and the groups my playbooks target (e.g. `webservers`, `db_prod`) - The connection details (SSH user, bastion, region, credentials method) Your job: 1. **Pick the plugin** — recommend the right inventory plugin (`amazon.aws.aws_ec2`, `google.cloud.gcp_compute`, `azure.azcollection.azure_rm`) or a custom executable script, and why. 2. **Write the inventory config** — produce the `*.aws_ec2.yml` (or equivalent) with `plugin`, `regions`, filters, and credentials sourcing. 3. **Recreate the groups** — use `keyed_groups` and `groups` (conditional) to reproduce my existing group names from tags/labels so playbooks keep targeting the same names. 4. **Map connection vars** — set `compose`/`hostnames` so `ansible_host`, SSH user, and bastion/proxy come through correctly. 5. **Preserve group_vars** — confirm `group_vars/` still binds to the dynamically created group names, and adjust where names differ. 6. **Cache and verify** — enable inventory caching for speed, and show `ansible-inventory -i <file> --graph` and `--list` to confirm hosts and groups before any playbook run. Output as: (a) chosen plugin with rationale, (b) the inventory YAML config, (c) the `keyed_groups`/`groups` mapping table, (d) the verification commands (`ansible-inventory --graph`, `ansible all -i ... -m ping`). Verify the generated inventory with `ansible-inventory --graph` and a `ping` before running real plays, so a tag typo doesn't silently target the wrong fleet.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Safe Ansible Rolling Update with Serial and Check Mode Prompt
Design a zero-downtime rolling update play that batches hosts with serial, drains load balancers, runs health checks, and fails fast with max_fail_percentage.
-
Ansible Dynamic Inventory Plugin Authoring Prompt
Draft a custom dynamic inventory plugin that builds hosts, groups, and vars from an external source, with caching and a verifiable graph output.
-
Ansible Undocumented Inventory and Playbook Documentation Prompt
Reverse-engineer an undocumented inventory and playbook set into a clear README, variable reference, and a Mermaid run-flow diagram.
-
Ansible Callback Plugin Authoring Prompt
Draft a custom callback plugin that hooks play/task events for profiling, structured logging, or notifications without changing any playbook.
More Ansible prompts & error guides
Browse every Ansible 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.