kubernetes/kops · error
unable to expand the template: %s, error: %s
Error message
unable to expand the template: %s, error: %s
What it means
Returned by RunToolBoxTemplate of `kops toolbox template` when expandFiles() fails to expand one of the --template-path globs/paths into concrete files. The path is first passed through utils.ExpandPath (~ expansion), so the failure typically means the glob matched nothing or the path is unreadable/not a valid template file. The offending path and underlying error are embedded in the message.
Source
Thrown at cmd/kops/toolbox_template.go:147
// @check if we are just rendering the config value
if options.configValue != "" {
v, found := context[options.configValue]
switch found {
case true:
fmt.Fprintf(out, "%v\n", v)
default:
fmt.Fprintf(out, "null\n")
}
return nil
}
// @step: expand the list of templates into a list of files to render
var templates []string
for _, x := range options.templatePath {
list, err := expandFiles(utils.ExpandPath(x))
if err != nil {
return fmt.Errorf("unable to expand the template: %s, error: %s", x, err)
}
templates = append(templates, list...)
}
snippets := make(map[string]string)
for _, x := range options.snippetsPath {
list, err := expandFiles(utils.ExpandPath(x))
if err != nil {
return fmt.Errorf("unable to expand the snippets: %s, error: %s", x, err)
}
for _, j := range list {
content, err := os.ReadFile(j)
if err != nil {
return fmt.Errorf("unable to read snippet: %s, error: %s", j, err)
}
snippets[path.Base(j)] = string(content)
}View on GitHub (pinned to 4c8573c808)
Solutions
- Verify the path exists: ls the --template-path value from the same working directory the command runs in
- Use absolute paths or check the current directory; remember ~ is expanded but plain relative paths are cwd-dependent
- If using a glob, confirm it actually matches files (test with `ls <glob>`)
- Check file/directory read permissions for the user running kops
- Ensure templates are present in CI containers/images before the toolbox command runs
Example fix
// before kops toolbox template --template-path ./templaes --snippets ./snippets --values values.yaml // after kops toolbox template --template-path ./templates --snippets ./snippets --values values.yaml
Defensive patterns
Strategy: validation
Validate before calling
for _, p := range templatePaths {
expanded := utils.ExpandPath(p)
matches, err := filepath.Glob(expanded)
if err != nil || len(matches) == 0 {
return fmt.Errorf("template path %q matches no files", p)
}
} Prevention
- Run the command from the directory where relative paths resolve, or use absolute paths
- Test globs with `ls <glob>` before running kops toolbox template
- Commit or mount template directories before CI steps that render them
When it happens
Trigger: `kops toolbox template --template-path ./templates` (or a glob like ./templates/*.yaml) where the directory/file does not exist, the glob matches zero files, the path lacks read permission, or expandFiles encounters a filesystem error walking the path.
Common situations: Running the command from the wrong working directory so relative template paths don't resolve; typo in --template-path; glob pattern with no matches; templates directory not checked out / mounted in CI; missing read permissions.
Related errors
- unable to expand the snippets: %s, error: %s
- error reading user provided private key %q: %v
- reading encryption config %v: %v
- error reading SSH public key %v: %v
- reading file %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/0caf57652e5ad2e1.
Report an issue: GitHub.