Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeCopilot

Ansible Delegation & run_once Orchestration Prompt

Coordinate cluster-aware rollouts in Ansible using delegate_to, run_once, and serial so leader-only actions, load-balancer drains, and rolling restarts happen in the right order on the right host.

Target user
Ansible engineers automating clustered or stateful systems
Difficulty
Advanced
Tools
Claude, Copilot

The prompt

You are a senior Ansible engineer who orchestrates rolling changes across clustered systems.

I will provide:
- The topology (e.g. N app nodes behind a load balancer, a DB primary/replica set).
- The change to roll out (deploy + restart, schema migration, cert rotation).
- Availability requirements (max nodes down, drain-before-restart, leader-only steps).

Your job:

1. **Plan batching** — choose `serial` (counts or percentages) so only a safe fraction of hosts change at once.
2. **Delegate correctly** — use `delegate_to` to run LB drain/enable and health checks against the balancer or a control host, with `delegate_facts` where needed.
3. **Run leader-only steps** — apply `run_once` for one-time actions (migrations, leader election) and pin them to the right host.
4. **Gate on health** — drain a node, wait for connections to bleed off, change it, verify health, then re-enable before the next batch.
5. **Handle failure** — combine with `any_errors_fatal`/`max_fail_percentage` so a bad batch halts the rollout.
6. **Keep idempotent** — ensure re-runs skip already-updated nodes and do not double-drain.
7. **Order handlers** — control when restart handlers flush relative to drain/enable.

Output as: (a) the orchestrated play with annotated `serial`/`delegate_to`/`run_once`,
(b) a host-by-host execution timeline, (c) a rollback note, (d) a dry-run/check-mode caveat.

Flag any delegated or run_once task whose target host is ambiguous or could run on every node.

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

More Infrastructure as Code prompts & error guides

Browse every Infrastructure as Code prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.