Hello, guys. I want to know why the variables defined in the configuration file below fail. The NSLOOKUP above can be parsed normally. Is there any good solution
1 Like
job "docs" {
datacenters = ["dc1"]
type = "service"
group "example" {
network {
port "http" {
static = "5678"
}
}
task "server" {
driver = "docker"
template {
# 弹性搜索在更改时自动重新加载文件,因此无需任何信号
change_mode = "noop"
data = <<EOF
# {{- range service (printf "%s-discovery|passing" (env "NOMAD_JOB_NAME")) }}{{ .Address }}:{{ .Port }}{{ end }}
## {{- range service (printf (env "NOMAD_JOB_NAME")) }}{{ .Address }}:{{ .Port }}{{ end }}
### {{- range service (env "NOMAD_JOB_NAME") }}{{ .Address }}:{{ .Port }}{{ end }}
# {{ range service "docs" }}{{ .Address }}:{{ .Port }},{{ end }}
initial_master_nodes:
- {{ env "NOMAD_IP_communication" }}:{{ env "NOMAD_HOST_PORT_communication" }}
EOF
destination = "local/elasticsearch.yml"
}
config {
image = "hashicorp/http-echo"
ports = ["http"]
args = [
"-listen",
":5678",
"-text",
"hello world",
]
}
service {
name = "${JOB}"
port = "http"
}
}
}
}
This is the result of my test. Both of the following should be available
{{- range service (printf (env "NOMAD_JOB_NAME")) }}{{ .Address }}:{{ .Port }}{{ end }}
{{- range service (env "NOMAD_JOB_NAME") }}{{ .Address }}:{{ .Port }}{{ end }}