Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Delegation

Direct 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.

When to use this

Use it when configuring, checking or troubleshooting Delegation in Ansible.

First 30 seconds

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.

Operational verification

task → delegated host → affects target

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Ansible automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformAnsible automation · Delegation owns Ansible alternate-execution-host semantics. Shared service/platform behavior remains in target domains.
Scope / prerequisiteUse it when configuring, checking or troubleshooting Delegation in Ansible.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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_to running on localhost with the wrong variables or Python.
Evidence references

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.

observation · 1
Key points
  • 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.
Key checks
  • 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docAnsible automation current

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%
Terminology layer

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.

Aliases that resolve here
ansible delegationdelegate_tolocal_actiondelegated task
Embedded reference data

Quick lookup tables

Delegation Ansible boundary map

Fast input/selection, execution/result and target-proof boundaries for Delegation.

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
Confirmation

Confirm action

Continue?