{"record":{"id":"96a10e61c56f6223","repo":"hashicorp/nomad","slug":"invalid-hosts-entry-q","errorCode":null,"errorMessage":"invalid hosts entry %q","messagePattern":"invalid hosts entry %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/shared/hostnames/mount.go","lineNumber":51,"sourceCode":"::1 localhost\n::1 ip6-localhost ip6-loopback\nfe00::0 ip6-localnet\nff00::0 ip6-mcastprefix\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters\nff02::3 ip6-allhosts\n\n# this entry is the IP address and hostname of the allocation\n# shared with tasks in the task group's network\n%s %s\n`, hostsCfg.Address, hostsCfg.Hostname)\n\n\tif len(extraHosts) > 0 {\n\t\tcontent.WriteString(\"\\n# these entries are extra hosts added by the task config\")\n\t\tfor _, hostLine := range extraHosts {\n\t\t\thostsEntry := strings.SplitN(hostLine, \":\", 2)\n\t\t\tif len(hostsEntry) != 2 {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid hosts entry %q\", hostLine)\n\t\t\t}\n\t\t\tif net.ParseIP(hostsEntry[1]) == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid IP address %q\", hostLine)\n\t\t\t}\n\t\t\tcontent.WriteString(fmt.Sprintf(\"\\n%s %s\", hostsEntry[1], hostsEntry[0]))\n\t\t}\n\t\tcontent.WriteString(\"\\n\")\n\t}\n\n\tpath := filepath.Join(taskDir, \"hosts\")\n\n\t// tasks within an alloc should be able to share and modify the file, so\n\t// only write to it if it doesn't exist\n\tif _, err := os.Stat(path); os.IsNotExist(err) {\n\t\terr := os.WriteFile(path, []byte(content.String()), 0644)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/shared/hostnames/mount.go#L33-L69","documentation":"GenerateEtcHostsMount builds a synthetic /etc/hosts mount for a task. Each entry in the task's extra_hosts annotation must be of the form \"hostname:IP\"; it splits on the first colon and requires exactly two parts. An entry without a colon (or with more than one, though SplitN bounds it) produces this error.","triggerScenarios":"A task's ExtraHosts (docker --add-host equivalent) contains a string with no \":\" separator, e.g. \"myhost\" instead of \"myhost:192.168.1.10\", passed through createContainerConfig when the driver sets up the container.","commonSituations":"Job authors typo the extra_hosts stanza (space instead of colon); copy Docker Compose syntax where mapping order/IP format differs; templating produces empty strings which split to one part; IPv6 addresses with colons confuse expectations when the hostname part is omitted.","solutions":["Fix the task config so every extra_hosts entry is \"hostname:IP\", e.g. \"myhost:192.168.1.10\"","Log or print the full extra_hosts list and find the entry lacking a colon","Trim whitespace/empty entries from the list before submitting the job","If generating the job from a template, validate the mapping produces colon-joined strings"],"exampleFix":"// before (job HCL)\nextra_hosts = [\"myhost\"]\n// after\nextra_hosts = [\"myhost:192.168.1.10\"]","handlingStrategy":"validation","validationCode":"func validExtraHosts(hosts []string) error {\n    for _, h := range hosts {\n        parts := strings.SplitN(h, \":\", 2)\n        if len(parts) != 2 { return fmt.Errorf(\"extra host %q must be hostname:IP\", h) }\n        if ip := net.ParseIP(parts[1]); ip == nil { return fmt.Errorf(\"extra host %q has invalid IP %q\", h, parts[1]) }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write extra_hosts as \"hostname:IP\" with a literal colon","Trim and drop empty strings from templated host lists before job submission","Lint job specs in CI with a validator that checks each entry splits into two parts"],"tags":["docker","networking","etc-hosts","config-validation"],"backgroundTag":"invalid-config-value","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"}