kubernetes/kops · error
unable to write template: %s
Error message
unable to write template: %s
What it means
After successfully opening the output file (or writing to stdout), RunToolBoxTemplate writes the rendered content with iowriter.Write. If the write fails, this error wraps the underlying write error. Rare for stdout, more plausible for files when disk is full or descriptors are bad.
Source
Thrown at cmd/kops/toolbox_template.go:226
documents = append(documents, string(formatted))
}
}
// join in harmony all the YAML documents back together
content := strings.Join(documents, "---\n")
iowriter := out
// @check if we are writing to a file rather than stdout
if options.outputPath != "" {
w, err := os.OpenFile(utils.ExpandPath(options.outputPath), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0o660)
if err != nil {
return fmt.Errorf("unable to open file: %s, error: %v", options.outputPath, err)
}
defer try.CloseFile(w)
iowriter = w
}
if _, err := iowriter.Write([]byte(content)); err != nil {
return fmt.Errorf("unable to write template: %s", err)
}
return nil
}
// newTemplateContext is responsible for loading the --values and build a context for the template
func newTemplateContext(files []string, values []string, stringValues []string) (map[string]interface{}, error) {
context := make(map[string]interface{})
for _, x := range files {
list, err := expandFiles(utils.ExpandPath(x))
if err != nil {
return nil, err
}
for _, j := range list {
content, err := os.ReadFile(j)
if err != nil {
return nil, fmt.Errorf("unable to configuration file: %s, error: %s", j, err)View on GitHub (pinned to 4c8573c808)
Solutions
- Check free disk space (df -h) and clean up if full.
- Verify the output filesystem is writable and healthy.
- Write to stdout and redirect as a workaround to confirm the failure is storage-related.
Example fix
// before kops toolbox template --out /mnt/full-disk/out.yaml // after df -h /mnt/full-disk # free space, then retry kops toolbox template --out /mnt/full-disk/out.yaml
Defensive patterns
Strategy: try-catch
Validate before calling
if st, err := os.Stat(filepath.Dir(outPath)); err == nil && st.IsDir() { // ensure free space
cmd := exec.Command("df", "-h", filepath.Dir(outPath)); _ = cmd.Run() } Try / catch
err := run("kops", "toolbox", "template", "--out", p)
if err != nil && strings.Contains(err.Error(), "unable to write template") { check disk space / fs health before retrying } Prevention
- Monitor disk space on CI runners
- Avoid writing rendered templates to network or read-only mounts
- Fall back to stdout output when file writes are unreliable
When it happens
Trigger: `kops toolbox template --out <file>` where the write syscall fails: disk full, I/O error, or the file handle becomes invalid during write.
Common situations: Full disk on CI runners; network filesystem issues; quota exceeded.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- unable to open file: %s, error: %v
- error reading addons file %s: %v
- error reading file %q: %v
- error reading SSH key file %q: %v
- error reading SSH public key files %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/a00b72cfeeca17e9.
Report an issue: GitHub.