{"record":{"id":"0a13b8909ba344d8","repo":"hashicorp/nomad","slug":"failed-to-build-template-manager-v","errorCode":null,"errorMessage":"failed to build template manager: %v","messagePattern":"failed to build template manager: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/taskrunner/template_hook.go","lineNumber":290,"sourceCode":"\t}\n\n\t// neither vault or nomad token has been updated, nothing to do\n\tif req.VaultToken == h.vaultToken && req.NomadToken == h.nomadToken {\n\t\treturn nil\n\t} else {\n\t\th.vaultToken = req.VaultToken\n\t\th.nomadToken = req.NomadToken\n\t}\n\n\ttmpls := h.templateManager.Templates()\n\n\t// shutdown the old template\n\th.templateManager.Stop()\n\th.templateManager = nil\n\n\terr := h.renderTemplates(ctx, nil, tmpls)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"failed to build template manager: %v\", err)\n\t\th.logger.Error(\"failed to build template manager\", \"error\", err)\n\t\t_ = h.config.lifecycle.Kill(context.Background(),\n\t\t\tstructs.NewTaskEvent(structs.TaskKilling).\n\t\t\t\tSetFailsTask().\n\t\t\t\tSetDisplayMessage(fmt.Sprintf(\"Template update %v\", err)))\n\t}\n\n\treturn nil\n}\n\n// renderTemplates creates the template managers and waits until each template has rendered, setting the watch\n// templateManger on the hook when complete so it can be referenced during token updates.\nfunc (h *templateHook) renderTemplates(ctx context.Context, once []*structs.Template, watch []*structs.Template) error {\n\tonceMgr, unblockOne, err := h.newManager(once)\n\tif err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/taskrunner/template_hook.go#L272-L308","documentation":"During a job Update (template contents changed in-place), the old template manager is stopped and renderTemplates is called to build a new one. If manager creation fails (e.g. the newManager checks like missing vault config fail), the error is wrapped with this prefix, logged, and the task is killed because templates can no longer render.","triggerScenarios":"A live job update changes template blocks such that rebuilding the manager fails — most commonly the updated task references a Vault cluster with no client config (see newManager check) or an invalid consul cluster.","commonSituations":"Editing a job in place to add/retarget vault or consul blocks without updating client agent configs first; invalid template options introduced in the updated template stanza.","solutions":["Fix the underlying cause logged after this prefix (usually vault/consul cluster config missing on clients)","Update client agent config with the referenced cluster before nomad job run","Stop and resubmit the job fresh if in-place update state is inconsistent","Validate the updated template stanza (name, change_mode, source) is well-formed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# validate the UPDATED job before the in-place update\nnomad job validate updated.nomad.hcl\nnomad job plan updated.nomad.hcl","typeGuard":null,"tryCatchPattern":"err := h.renderTemplates(ctx, nil, tmpls)\nif err != nil {\n    wrapped := fmt.Errorf(\"failed to build template manager: %w\", err)\n    h.logger.Error(\"template update failed; task will be killed\", \"error\", wrapped)\n    _ = h.config.lifecycle.Kill(ctx, structs.NewTaskEvent(structs.TaskKilling).SetFailsTask().SetDisplayMessage(wrapped.Error()))\n    return wrapped // surface the root cause, not just the wrapper\n}","preventionTips":["Run nomad job plan before any in-place template stanza changes","Keep vault/consul cluster configs present on all client pools the job can schedule to","Stop and resubmit jobs (rather than live-update) when changing vault cluster targets","Monitor alloc events for template update kills"],"tags":["template","nomad","update","configuration"],"backgroundTag":"template-manager-build-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"}