{"record":{"id":"e9bb8630755e00be","repo":"hashicorp/nomad","slug":"error-parsing-advertise-address-template-v","errorCode":null,"errorMessage":"Error parsing advertise address template: %v","messagePattern":"Error parsing advertise address template: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/config.go","lineNumber":2532,"sourceCode":"\treturn addrs, err\n}\n\n// normalizeAdvertise returns a normalized advertise address.\n//\n// If addr is set, it is used and the default port is appended if no port is\n// set.\n//\n// If addr is not set and bind is a valid address, the returned string is the\n// bind+port.\n//\n// If addr is not set and bind is not a valid advertise address, the hostname\n// is resolved and returned with the port.\n//\n// Loopback is only considered a valid advertise address in dev mode.\nfunc normalizeAdvertise(addr string, bind string, defport int, dev bool) (string, error) {\n\taddr, err := listenerutil.ParseSingleIPTemplate(addr)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error parsing advertise address template: %v\", err)\n\t}\n\n\tif addr != \"\" {\n\t\t// Default to using manually configured address\n\t\t_, _, err = net.SplitHostPort(addr)\n\t\tif err != nil {\n\t\t\tif !isMissingPort(err) && !isTooManyColons(err) {\n\t\t\t\treturn \"\", fmt.Errorf(\"Error parsing advertise address %q: %v\", addr, err)\n\t\t\t}\n\n\t\t\t// missing port, append the default\n\t\t\treturn normalizeAddrWithPort(addr, defport), nil\n\t\t}\n\n\t\treturn ipaddr.NormalizeAddr(addr), nil\n\t}\n\n\t// Fallback to bind address first, and then try resolving the local hostname","sourceCodeStart":2514,"sourceCodeEnd":2550,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/config.go#L2514-L2550","documentation":"normalizeAdvertise() runs the configured advertise address through listenerutil.ParseSingleIPTemplate, which processes Go/consul-template style templates like {{ GetPrivateIP }}. This error wraps any failure of that template parsing, meaning the advertise string contained template syntax that could not be evaluated or produced an invalid value.","triggerScenarios":"The 'advertise' or 'advertise_reconnect_timeout' setting in the agent config contains a template expression (e.g. {{ GetPrivateInterfaces | attr \"address\" }}) that fails to parse or evaluate — malformed template syntax, an unknown template function, or a function returning no value.","commonSituations":"Copy-pasted template snippets from docs with typos ({{ GetPrviateIP }}), running Consul on a host with no routable private interface so a template function errors, or quoting issues in JSON/HCL config that mangle the braces.","solutions":["Check the advertise value in your config for typos in template function names and correct {{ }} syntax","Replace the template with a literal IP:port (e.g. advertise = \"10.0.0.5:8301\") to bypass template evaluation","Verify the node actually has an interface the template function can resolve (e.g. GetPrivateIP fails on hosts without one)","Update Consul if using a template function not supported by your version"],"exampleFix":"// before\nadvertise = \"{{ GetPrviateIP }}\"\n// after\nadvertise = \"{{ GetPrivateIP }}\"","handlingStrategy":"validation","validationCode":"addr := os.Getenv(\"CONSUL_ADVERTISE\")\nif strings.Contains(addr, \"{{\") {\n    if !strings.HasSuffix(strings.TrimSpace(addr), \"}}\") {\n        return fmt.Errorf(\"advertise template braces unbalanced: %q\", addr)\n    }\n}\n// prefer a literal IP to skip template parsing entirely","typeGuard":null,"tryCatchPattern":"addr, err := normalizeAdvertise(cfg.Advertise, cfg.BindAddr, 8301, dev)\nif err != nil {\n    if strings.Contains(err.Error(), \"template\") {\n        log.Warn(\"advertise template failed, falling back to explicit IP\")\n        addr, err = normalizeAdvertise(myPrivateIP, cfg.BindAddr, 8301, dev)\n    }\n    if err != nil { return err }\n}","preventionTips":["Use literal IP:port for advertise in production configs","Keep a lint step that regex-checks {{ }} balance in config values","Pin known-good template functions for your Consul version","Test config load (consul validate) before deploys"],"tags":["config","consul","template-parsing","advertise-address"],"backgroundTag":"template-parsing-failed","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"}