Delegation
Cheat sheet · https://pcornel.dk/topic.php?topic=5415
Answer
Ansible delegation executes a task on another host while the play remains logically associated with the current inventory host, creating separate variable and execution-host contexts.
Remember
- Play host ≠ execution host when delegate_to/local_action is used.
- Variables from current host ≠ delegated host facts automatically; context rules matter.
- Delegated task success ≠ original host changed; side effect can occur on controller or shared service.
- Parallel delegation to shared target ≠ race-free; many hosts can delegate concurrently.
First checks
- delegate_to: localhost / <host> — run elsewhere
- run_once: true — single execution
- Delegated facts — scope
Verify in this order
task → delegated host → affects target
Where it usually breaks
Delegated task success proves an action completed on the delegated execution host for a current-host context; it does not prove the original host was modified or shared-state races are absent.
Inventory/vars → play/task selection → connection/become → module request → module result → target object read-back → handler/service effective state → workload verification.
Delegation Ansible boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Inputs / selection | Correct inventory, hosts, variables/facts and content are explicit | Wrong scope, stale facts, hidden precedence or content-version drift |
| Execution | Connection, privilege, module/task context and ordering match intent | Unreachable, wrong execution host, privilege/plugin failure or misleading skip/change state |
| Result semantics | Per-host/item results are preserved and interpreted correctly | Aggregate recap hides partial/skipped/handled failures |
| Target proof | Resource/workload read-back and rerun confirm convergence | Green Ansible status treated as end-to-end acceptance |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5415