Node Targeting
A step with nodes runs once on every node its label selector matches. A DAG with node: required runs bound to one node, so a whole workflow can run node by node. Nodes come from the node inventory: SSH hosts, and workers that set an ID.
INFO
Node targeting requires Dagu 2.28.0 or later.
Run a Step on Matched Nodes
steps:
- id: clean_cache
run: rm -rf /tmp/app-cache
nodes: web,env=prodWhen the step starts, after its dependencies and preconditions, Dagu matches the selector against the nodes. Each enabled matched node gets its own child run, bound to that node. The run command runs on each node over SSH.
Selectors
A selector is the label filter that dagu history --labels takes: terms separated by commas, all of which a node's labels must match.
| Term | Matches |
|---|---|
web | Nodes with the label web |
env=prod | Nodes with env set to prod |
region=us-* | Globs with * and ?, in keys and values |
!canary, !env=dev | Nodes that do not match the term |
A comma means AND. Selectors match labels, never node names. To run on named nodes, narrow the run.
nodes takes a string, a list of terms, or an object:
steps:
- id: as_string
run: uptime
nodes: web,env=prod
- id: as_list
run: uptime
nodes: [web, "!canary"]
- id: as_object
run: uptime
nodes:
labels: web,env=prod
max_concurrent: 5
keep_going: true| Field | Default | Meaning |
|---|---|---|
labels | Required | A selector, as a string or a list of terms |
max_concurrent | 1 | Nodes running at once, 1 to 1000 |
keep_going | false | Whether the remaining nodes start after one fails |
Quote a selector that starts with !, since YAML reads a leading ! as a tag.
References in a Selector
A selector can hold references, such as env=${params.env}. Each part of a term that holds a reference must resolve to one label key or value. A value cannot add a term, negate one, or widen the match: env=${params.env} works with prod and fails with prod,!canary.
A selector with a reference is checked when the step starts. Every other selector is checked by dagu validate.
Matching
- The matched nodes run in name order.
- A step matches at most 1,000 nodes.
- A disabled node does not run.
- A step fails before any node starts when its selector matches no nodes (
selector matched no nodes), only disabled nodes, or more than 1,000.
Steps That Take Nodes
nodes is allowed on a dag.run step and on command steps:
run,command, orscriptwith noactionssh.runsftp.uploadandsftp.download
A step with nodes runs on each node, so a DAG-level ssh or container does not apply to it. dagu validate fails, naming the field, when:
nodesis on any other step, or on a step that also setsparallel,foreach,worker_selector,container, orrepeat_policy;- an
ssh.runorsftp.*step withnodessetswith.hostorwith.ip, since each node gives the host; - a step with
nodessetswith.shell_packages; - an
sftp.downloadstep withnodeshas awith.destinationthat does not use${node.name}, since every node would write the same local path; - a DAG with a
workspacelabel has a step withnodesor setsnode: required.
steps:
- id: collect_logs
action: sftp.download
with:
source: /var/log/app/app.log
destination: /srv/logs/${node.name}/app.log
nodes: webCommand Steps
On a command step, each node's child run runs the step alone, in a node: required DAG with the parent DAG's settings. The step reads what it would read without nodes: the parent run's params, its env, and the outputs of earlier steps.
timeout_secandretry_policyapply to each node's run of the step.depends,preconditions,continue_on, andoutputapply to the step as a whole.
Concurrency and Failures
Nodes start in name order, at most max_concurrent at a time. defaults.max_concurrent does not apply.
- With
keep_going: false, no node starts after a node fails. The nodes running finish, and the rest do not start. - With
keep_going: true, every node runs. - Either way, the step fails when a node failed.
continue_ondecides whether the steps after it run. - Aborting the step stops the nodes not started and aborts the running child runs.
Aggregate Output
The step writes an aggregate to its standard output, as parallel does, with one entry per matched node in name order. Each entry adds node.
{
"summary": {"total": 3, "succeeded": 1, "failed": 1},
"results": [
{"node": "web01", "name": "deploy-one", "dagRunId": "...", "status": "failed"},
{"node": "web02", "status": "disabled"},
{"node": "web03", "name": "deploy-one", "dagRunId": "...", "status": "not_started"}
],
"outputs": []
}A node that did not run has the status not_started, disabled, or removed, and counts in summary.total only. When the aggregate would exceed max_output_size, its entries and outputs leave out the outputs; each child run keeps its own.
Run a Workflow on Each Node
To run several steps on one node before the next node starts, put them in a node: required DAG and start it from a dag.run step with nodes:
params:
- version: ""
steps:
- id: rollout
action: dag.run
with:
dag: deploy-one
params:
version: ${params.version}
nodes:
labels: web,env=prod
max_concurrent: 1
---
name: deploy-one
node: required
params:
- version: ""
steps:
- id: drain
action: http.request
with:
method: POST
url: https://lb.internal/pools/web/${node.name}/drain
- id: install
depends: [drain]
run: sudo apt-get install -y "app=${params.version}"
- id: restart
depends: [install]
run: sudo systemctl restart apphttp.request runs where the run runs. The run steps run on the node over SSH.
- The child DAG must declare
node: required. Otherwise the step fails before any child starts. - The child reads only the params passed to it under
with.params. node: requiredmakes a DAG run only bound to one node: as the child of adag.runstep withnodes, or started with one node.requiredis its only value.- A
node: requiredDAG cannot setssh,container, orworker_selector(localincluded), and cannot have a step withnodes.
To run one step on every node before the next step starts, set nodes on each command step instead.
Bound Runs
A run bound to an SSH node reaches the node as a run with DAG-level ssh reaches its host.
- Steps with no action,
ssh.run, andsftp.*connect to the node, through its bastion. This includes handlers andforeachbodies. - Other actions, such as
http.request, run where the run runs. - Fields under the
withof anssh.runorsftp.*step override the node's. A key or a password underwithreplaces all of the node's credentials. - A step that sets
with.hostorwith.ipconnects to that host, as it would outside a bound run. with.known_host_file,with.strict_host_key, andwith.bastionare errors. The node's inventory decides which host keys it accepts and which bastion it uses.
A run resolves its node's credentials once, before its first step, when any of its steps connects to the node. They join the run's masking. Each hop accepts only its own node's host_key or trusted key, unless the node sets strict_host_key: false. A refused key fails the step, naming the hop, before any credential is sent.
A child bound to an SSH node runs on the host that runs its parent, even when the default execution mode is distributed.
A bound run fails before any step starts when its node is not in the inventory or is disabled.
Node References
Every value-resolved field of a bound run can read its node:
| Reference | Value |
|---|---|
${node.name} | Node name |
${node.host} | Host. For a worker node, the host its worker reports |
${node.port} | Port, 22 when the node sets none. Empty for a worker node |
${node.user} | SSH user. Empty for a worker node |
${node.description} | Description. Empty for a worker node |
${node.labels} | Labels, sorted and comma-separated, as key or key=value |
${node.labels.<key>} | The value of the label with that key, empty for a label with no value |
${node.labels."<key>"} | The same, for a key with a dot, such as ${node.labels."gpu.type"} |
steps:
- id: report
run: echo "${node.name} at site ${node.labels.site}"
nodes: web- A reference to a label the node lacks fails the run before any step, naming the node and the key.
- A
${node.<path>}that the table does not list, such as${node.nmae}, fails the run before any step. - Outside a bound run, a
${node.*}reference is kept as text, with a notice. - A run with a variable named
node, such as a step output, reads${node.<path>}as a JSON path into that variable instead.
Dagu inserts these values into run: as shell text. Quote them, as in "${node.labels.site}".
Narrow a Run to Listed Nodes
A run can carry a list of node names. In every step with nodes of the run and of its child runs, a node runs only when the step's selector matches it and the list names it.
| Surface | List |
|---|---|
dagu start, dagu enqueue | --node, repeatable |
| API start, start-sync, and enqueue, for a DAG file or an inline spec | targetNodes |
MCP dagu_execute start and enqueue | targetNodes |
| Web UI run dialog | The Node field, for a node: required DAG only |
dagu start --node web01 --node web03 deployThe list is checked before the run exists, and a mistake fails the request:
- Each name must be a node, compared without case:
node "web1" is not a node of the project. - A DAG takes a list only when a step, a
foreachbody, or a handler setsnodesor runs a child DAG, or when it isnode: required. - A start of selected steps (
--only) takes no list.
A list only removes nodes. A step whose selector matches nodes, none of which the list names, is skipped, and the skip does not block the steps after it. A run fails with no listed node was selected when every step with nodes that matched nodes is left without a listed one, those of foreach bodies and dag.run child runs included. A step that matched no node, such as one a precondition skipped, does not count.
The run keeps the list in its status. Queued runs, retries, edit-and-retry runs, and dagu restart keep it. dagu start --from-run-id and the reschedule request keep it too, and check it again, so --from-run-id takes no --node. Run details carry the list as targetNodes. The run header shows it, unless it names only the node the run is bound to.
Child runs started by dag.run or dag.enqueue keep the list, on a worker too. A dag.run child runs where its parent runs, so in a narrowed run, a child DAG that selects workers fails the step that starts it.
Start a Bound DAG Directly
A node: required DAG started on its own takes exactly one node, an inventory node or a worker node, and the run is bound to it.
dagu start --node tokyo-web01 deploy-oneIn the Web UI, the run dialog of a node: required DAG has a Node field, which suggests enabled nodes and online worker nodes. The start and enqueue requests refuse such a DAG without exactly one node. dagu start and dagu enqueue record a run that fails before any step.
A worker selector given when such a DAG is started or enqueued is refused, since the bound node decides where it runs.
Worker Nodes
A step with nodes matches worker nodes as it matches SSH nodes. A child bound to a worker node runs on that worker, dispatched by its ID, and every step of it runs there.
- The node has no SSH connection. An
ssh.runorsftp.*step that sets nowith.hostorwith.ipfails the run before any step starts. - A matched worker that is offline when its child is dispatched fails its node at once:
worker node "tokyo-gw" is offline. - A worker lost during the child run fails its node, as a lost worker fails any run.
Runs Started Bound to a Worker Node
A node: required DAG started with --node or targetNodes naming a worker node runs on that worker. This holds for dagu start, dagu enqueue, dagu retry, dagu restart, the API start, start-sync, enqueue, retry, and edit-and-retry requests, the resume of a waiting run, and queued runs, whatever the default execution mode. It never runs on the Dagu host or on another worker.
- The run reaches its worker through a coordinator. With
coordinator.enabled: false, it fails before it starts, and a request gets503. - The run records the worker node it is bound to as
boundWorker. Retries, restarts, resumes, and edit-and-retry runs keep it. - A worker that is offline when the run is dispatched fails it at once:
worker node "tokyo-gw" is offline. A request fails with409. - When the name no longer names that worker, because the worker was forgotten or an inventory node took the name, the run fails rather than run on another node.
Runs on Workers
A step with nodes and a bound run behave on a worker as on the Dagu host.
- The worker reads from the coordinator the nodes a step's selector matches, a bound run's node and its bastion, and the host keys trusted for them.
- A node's secret refs resolve through the coordinator.
- Host keys are checked on the worker. A run never trusts a key.
- Children bound to SSH nodes run on the worker that runs their parent. Children bound to worker nodes run on those workers.
A worker that cannot reach the coordinator fails the step or the run, as an unreadable inventory does.
Retry Failed Nodes
A retry of a run, by dagu retry or the retry request, with or without --step, runs a step with nodes again only on the nodes that did not succeed.
dagu retry --run-id 20260115_020000 deploy- The step keeps the nodes it last recorded and does not match its selector again. A node added to the inventory since is not added.
- A node whose child run succeeded or partially succeeded keeps its result and does not run.
- Any other node runs its child run again, or starts it if it never started, with the connection settings and credentials the inventory holds now.
- A node disabled now does not run, and keeps its child run for a later retry.
- A node that has left the inventory, and whose child run did not succeed, is
removed. It does not run and does not fail the step. The step fails when every node it keeps is removed or disabled and none kept a result. - The retry does the same after the run's process died during the step.
A step whose previous attempt left no readable node records matches its selector again, with a warning in the run log. So does a step that the run reused from another run, as --reuse-from and edit-and-retry reuse steps.
In the Web UI, a step with nodes offers Retry failed nodes, with the number of its nodes that failed, were aborted, or did not start.
View Node Runs
The view of a run or sub-run that has node runs has a Nodes tab: one row per node, with its run for each step with nodes. Rows with a failed, aborted, or rejected run come first. Failed only keeps those rows. Open a row's run to see its steps and logs. The step details show the step's node counts by status.
Over the API, GET /api/v1/dag-runs/{name}/{dagRunId}/node-runs lists the same rows, and failedOnly=true keeps the failed ones. See Node Endpoints. Run details carry each step's counts as nodeRuns, and a bound run's node as boundNode.
Limits
- A step runs on at most 1,000 nodes, and a DAG with a
workspacelabel cannot usenodesornode: required. - A child DAG whose name holds a reference, such as
dag: deploy-${params.app}, cannot read nodes or registry secrets when it runs on a worker with its parent. Use a literal child name, or run the parent on the Dagu host. A child dispatched to a worker, such as one withworker_selectoror bound to a worker node, is not affected.
See Also
- Node Inventory: define nodes, credentials, and host keys
- Sub-DAGs:
dag.runandparallel - SSH and SFTP
- Distributed Execution

