{"record":{"id":"83ebde775fe911f9","repo":"hashicorp/nomad","slug":"template-d-validation-failed-s","errorCode":null,"errorMessage":"Template %d validation failed: %s","messagePattern":"Template (.+?) validation failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":8335,"sourceCode":"\tfor idx, artifact := range t.Artifacts {\n\t\tif err := artifact.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Artifact %d validation failed: %v\", idx+1, err)\n\t\t\tmErr.Errors = append(mErr.Errors, outer)\n\t\t}\n\t}\n\n\t// Validate Vault.\n\tif t.Vault != nil {\n\t\tif err := t.Vault.Validate(); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Vault validation failed: %v\", err))\n\t\t}\n\t}\n\n\t// Validate templates.\n\tdestinations := make(map[string]int, len(t.Templates))\n\tfor idx, tmpl := range t.Templates {\n\t\tif err := tmpl.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Template %d validation failed: %s\", idx+1, err)\n\t\t\tmErr.Errors = append(mErr.Errors, outer)\n\t\t}\n\n\t\tif other, ok := destinations[tmpl.DestPath]; ok {\n\t\t\touter := fmt.Errorf(\"Template %d has same destination as %d\", idx+1, other)\n\t\t\tmErr.Errors = append(mErr.Errors, outer)\n\t\t} else {\n\t\t\tdestinations[tmpl.DestPath] = idx + 1\n\t\t}\n\t}\n\n\t// Validate actions.\n\tactions := make(map[string]bool)\n\tfor _, action := range t.Actions {\n\t\tif err := action.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Action %s validation failed: %s\", action.Name, err)\n\t\t\tmErr.Errors = append(mErr.Errors, outer)\n\t\t}","sourceCodeStart":8317,"sourceCodeEnd":8353,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L8317-L8353","documentation":"Nomad's Task.Validate wraps each template block validation failure in \"Template %d validation failed: %s\" (1-based index) and appends it to the job's multi-error. The underlying message comes from Template.Validate and describes what is wrong (e.g. missing dest_path, bad splay, invalid source). It is returned by job validation endpoints and surfaces in CLI output such as `nomad job run` or `nomad job allocs` error text.","triggerScenarios":"Submitting a job whose task stanza contains a template block that fails Template.Validate: missing destination, template source referencing missing artifact, invalid splay duration, embedded template parse errors, or duplicate/invalid env targets.","commonSituations":"Typo in template stanza fields; using consul-template functions unsupported by the Nomad version; dest_path pointing outside the task dir with wrong permissions; misconfigured change_mode/change_script options.","solutions":["Read the wrapped inner error (after 'validation failed: ') to see which template field is wrong","Fix the offending field in the Nth template block (index is 1-based per task)","Run `nomad job validate <jobfile>` before submitting to catch all template errors at once","Check Nomad version docs for template options supported in your deployment"],"exampleFix":"// before\ntemplate {\n  data = \"{{ env \\\"attr.unique.network.ip-address\\\" }}\"\n}\n// after (missing dest_path added)\ntemplate {\n  data      = \"{{ env \\\"attr.unique.network.ip-address\\\" }}\"\n  destination = \"local/ip.txt\"\n}","handlingStrategy":"validation","validationCode":"for i, tmpl := range task.Templates {\n    if err := tmpl.Validate(); err != nil {\n        return fmt.Errorf(\"template %d: %w\", i+1, err)\n    }\n}","typeGuard":"func hasTemplates(t *structs.Task) bool { return len(t.Templates) > 0 }","tryCatchPattern":"if err := job.Validate(); err != nil {\n    var mErr structs.MultiError\n    if errors.As(err, &mErr) {\n        for _, e := range mErr.Errors {\n            if strings.Contains(e.Error(), \"Template \") { /* handle */ }\n        }\n    }\n}","preventionTips":["Run `nomad job validate` in CI before every submit","Always set destination on every template block","Pin consul-template feature usage to your Nomad version"],"tags":["nomad","job-validation","template","hcl"],"backgroundTag":"job-spec-validation-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}