Skip to content
CloudOps
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.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week