hashicorp/nomad · error

error opening env template: %v

Error message

error opening env template: %v

What it means

In loadTemplateEnv, a template marked envvars=true has a rendered destination file that cannot be opened via os.Open — typically the template rendered to a path that does not exist, was interpolated to a bad dest, or permissions deny reading. The whole env-loading pass fails, failing the task run hook.

Source

Thrown at client/allocrunner/taskrunner/template/template.go:1086

	user        string
	group       string
	taskID      string
	contents    []byte
}

// loadTemplateEnv loads task environment variables from all templates.
func loadTemplateEnv(tmpls []*structs.Template, taskEnv *taskenv.TaskEnv) (map[string]string, error) {
	all := make(map[string]string, 50)
	for _, t := range tmpls {
		if !t.Envvars {
			continue
		}

		// we checked escape before we rendered the file
		dest, _ := taskEnv.ClientPath(t.DestPath, true)
		f, err := os.Open(dest)
		if err != nil {
			return nil, fmt.Errorf("error opening env template: %v", err)
		}
		defer f.Close()

		// Parse environment fil
		vars, err := envparse.Parse(f)
		if err != nil {
			return nil, fmt.Errorf("error parsing env template %q: %v", dest, err)
		}
		maps.Copy(all, vars)
	}
	return all, nil
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Verify the template's destination path renders and exists before env parsing
  2. Check taskDir permissions and that ClientPath interpolation resolves inside the allocation dir
  3. Ensure the template actually rendered (DidRender) before loadTemplateEnv is invoked
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at client/allocrunner/taskrunner/template/template.go:1086 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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