Pcornel
Automation · Ansible

Delegation

Cheat sheet · https://pcornel.dk/topic.php?topic=5415

Back to the Topic

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

BoundaryHealthy evidenceSuspicious evidence
Inputs / selectionCorrect inventory, hosts, variables/facts and content are explicitWrong scope, stale facts, hidden precedence or content-version drift
ExecutionConnection, privilege, module/task context and ordering match intentUnreachable, wrong execution host, privilege/plugin failure or misleading skip/change state
Result semanticsPer-host/item results are preserved and interpreted correctlyAggregate recap hides partial/skipped/handled failures
Target proofResource/workload read-back and rerun confirm convergenceGreen 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

Confirmation

Confirm action

Continue?