hashicorp/nomad · error

Action %s defined multiple times

Error message

Action %s defined multiple times

What it means

Task.Validate tracks action names in a map and emits "Action %s defined multiple times" when the same action name appears in more than one action block within the same task. Duplicate names would make handler dispatch ambiguous, so it is rejected at validation.

Source

Thrown at nomad/structs/structs.go:8356

		if other, ok := destinations[tmpl.DestPath]; ok {
			outer := fmt.Errorf("Template %d has same destination as %d", idx+1, other)
			mErr.Errors = append(mErr.Errors, outer)
		} else {
			destinations[tmpl.DestPath] = idx + 1
		}
	}

	// Validate actions.
	actions := make(map[string]bool)
	for _, action := range t.Actions {
		if err := action.Validate(); err != nil {
			outer := fmt.Errorf("Action %s validation failed: %s", action.Name, err)
			mErr.Errors = append(mErr.Errors, outer)
		}

		if handled, seen := actions[action.Name]; seen && !handled {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Action %s defined multiple times", action.Name))
			actions[action.Name] = true
			continue
		}
		actions[action.Name] = false
	}

	// Validate the dispatch payload block if there
	if t.DispatchPayload != nil {
		if err := t.DispatchPayload.Validate(); err != nil {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Dispatch Payload validation failed: %v", err))
		}
	}

	// Validate the Lifecycle block if there
	if t.Lifecycle != nil {
		if err := t.Lifecycle.Validate(); err != nil {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Lifecycle validation failed: %v", err))
		}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Rename one of the duplicate action blocks so names are unique per task
  2. Merge the commands into one action script if they belong together
  3. Run `nomad job validate` to catch duplicates before submission

Example fix

// before
action "cleanup" {
  command = "/bin/a.sh"
}
action "cleanup" {
  command = "/bin/b.sh"
}
// after
action "cleanup-a" {
  command = "/bin/a.sh"
}
action "cleanup-b" {
  command = "/bin/b.sh"
}
Defensive patterns

Strategy: validation

Validate before calling

names := map[string]bool{}
for _, a := range task.Actions {
    if names[a.Name] { return fmt.Errorf("duplicate action %q", a.Name) }
    names[a.Name] = true
}

Try / catch

if err := job.Validate(); err != nil {
    if strings.Contains(err.Error(), "defined multiple times") { /* rename duplicates */ }
}

Prevention

When it happens

Trigger: A single task declares two `action` blocks with the identical `name`; generated or templated HCL duplicating action names.

Common situations: Copy-pasting an action block to add a second command while forgetting to rename it; programmatic job generation concatenating action lists.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/8d92537df9edac6d. Report an issue: GitHub.