{"record":{"id":"861931eab9e34020","repo":"kubernetes/kops","slug":"failed-to-update-etc-hosts-w","errorCode":null,"errorMessage":"failed to update /etc/hosts: %w","messagePattern":"failed to update /etc/hosts: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/nodeup/nodetasks/update_etc_hosts_task.go","lineNumber":92,"sourceCode":"func (_ *UpdateEtcHostsTask) RenderLocal(t *local.LocalTarget, a, e, changes *UpdateEtcHostsTask) error {\n\tetcHostsPath := \"/etc/hosts\"\n\n\tmutator := func(existing []string) (*hosts.HostMap, error) {\n\t\thostMap := &hosts.HostMap{}\n\t\tbadLines := hostMap.Parse(existing)\n\t\tif len(badLines) != 0 {\n\t\t\tklog.Warningf(\"ignoring unexpected lines in /etc/hosts: %v\", badLines)\n\t\t}\n\n\t\tfor _, record := range e.Records {\n\t\t\thostMap.ReplaceRecords(record.Hostname, record.Addresses)\n\t\t}\n\n\t\treturn hostMap, nil\n\t}\n\n\tif err := hosts.UpdateHostsFileWithRecords(etcHostsPath, mutator); err != nil {\n\t\treturn fmt.Errorf(\"failed to update /etc/hosts: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":74,"sourceCodeEnd":96,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/nodeup/nodetasks/update_etc_hosts_task.go#L74-L96","documentation":"The UpdateEtcHosts task rewrites /etc/hosts via hosts.UpdateHostsFileWithRecords, which reads the current file, applies the record mutator, and writes it back atomically. Any failure in that read-modify-write pipeline (unwritable file, read error, rename failure) is wrapped with %w into this error.","triggerScenarios":"RenderLocal calls UpdateHostsFileWithRecords(\"/etc/hosts\", mutator) and it errors: /etc read-only, /etc/hosts unreadable/corrupt, disk full preventing the temp-file+rename, or permission denied for the writing user.","commonSituations":"Immutable /etc/hosts (chattr +i, common on some container images and cloud-init templates), read-only rootfs, disk-full nodes, or running the task as a non-root user.","solutions":["Check for the immutable bit: lsattr /etc/hosts; remove with chattr -i /etc/hosts","Verify write permission on /etc and /etc/hosts for the nodeup user (root)","Check disk space (df -h) — atomic writes need free space for a temp file","Inspect the wrapped cause (%w) in the error chain to identify the exact OS error and fix accordingly"],"exampleFix":"# before\n$ lsattr /etc/hosts\n----i--------- /etc/hosts\n# after\n$ chattr -i /etc/hosts && kops-nodeup ...","handlingStrategy":"validation","validationCode":"// Pre-check on the node:\nsudo test -w /etc/hosts && echo writable || echo 'not writable'\nlsattr /etc/hosts | grep -q i && echo 'immutable /etc/hosts!' || true\ndf -h /etc | awk 'NR==2{exit ($5+0>95)?1:0}' || echo 'disk nearly full'","typeGuard":null,"tryCatchPattern":"if err := task.RenderLocal(...); err != nil {\n\tvar wrapped error\n\tif errors.As(err, &wrapped) || strings.Contains(err.Error(), \"failed to update /etc/hosts\") {\n\t\treturn fmt.Errorf(\"check immutability/permissions/space on /etc/hosts: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Never chattr +i /etc/hosts on node images","Run nodeup as root","Keep free disk space on the root filesystem","Validate /etc/hosts parses (no exotic lines) before runs"],"tags":["nodeup","etc-hosts","filesystem","permissions"],"backgroundTag":"etc-hosts-update-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}