Use it when configuring, checking or troubleshooting Delegation in Ansible.
Delegation
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.
1. Delegation runs a task on another host (API calls from localhost, load balancer changes).
2. run_once for single actions.
3. Facts belong to delegated host if delegate_facts.
4. Mind credentials.
5. Use for orchestration.
task → delegated host → affects target
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
current play host/context → delegate target → variable/context resolution → delegated connection/become → action/result → shared/original target read-back
Healthy evidence: current and delegated hosts are explicit, variable context is understood, side effects occur on the intended endpoint and concurrency is controlled.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: assuming task ran on play host, wrong delegated credentials, hostvar confusion, controller-only side effects or race conditions against shared targets.
Step 3 Common mistakes Narrow the fault
delegate_torunning on localhost with the wrong variables or Python.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- 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.
- delegate_to: localhost / <host> — run elsewhere
- run_once: true — single execution
- Delegated facts — scope
ReferenceWhat it is1 section · depth on demand
Core model
Track current inventory host, delegated host, delegated connection/become context, variable interpolation and result registration so side effects are attributed to the actual execution target.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
Delegated task success shows an action completed on the delegated execution host for a current-host context, but it does not show the original host was modified or shared-state races are absent.
In depth
Delegation runs a task on a different host than the one currently being processed, while still using that host's variables. It is used for API calls from the control node, updating a load balancer or monitoring system on behalf of each server, or running checks from a jump host.
- name: Remove server from load balancer pool
community.general.haproxy:
state: disabled
host: "{{ inventory_hostname }}"
backend: web
delegate_to: lb01
- name: Register device in NetBox
netbox.netbox.netbox_device:
netbox_url: "{{ nb_url }}"
netbox_token: "{{ nb_token }}"
data: { name: "{{ inventory_hostname }}", site: "{{ site }}" }
delegate_to: localhost
Use run_once: true with delegation for actions that should happen once per play, not once per host.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Ansible > Delegation. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Delegation Ansible boundary map
Fast input/selection, execution/result and target-proof boundaries for Delegation.
| 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 |