431c153cd9
This change modifies the template task runner to utilise the new consul-template which includes Nomad service lookup template funcs. In order to provide security and auth to consul-template, we use a custom HTTP dialer which is passed to consul-template when setting up the runner. This method follows Vault implementation. Co-authored-by: Michael Schurter <mschurter@hashicorp.com>
42 lines
842 B
HCL
42 lines
842 B
HCL
job "nomad_provider_service_lookup" {
|
|
datacenters = ["dc1"]
|
|
type = "service"
|
|
|
|
constraint {
|
|
attribute = "${attr.kernel.name}"
|
|
value = "linux"
|
|
}
|
|
|
|
group "nomad_provider_service_lookup" {
|
|
|
|
task "test" {
|
|
driver = "raw_exec"
|
|
|
|
config {
|
|
command = "bash"
|
|
args = ["-c", "sleep 15000"]
|
|
}
|
|
|
|
template {
|
|
data = <<EOH
|
|
{{ range nomadServices }}
|
|
service {{ .Name }} {{ .Tags }}{{ end }}
|
|
EOH
|
|
|
|
destination = "${NOMAD_TASK_DIR}/services.conf"
|
|
change_mode = "restart"
|
|
}
|
|
|
|
template {
|
|
data = <<EOH
|
|
{{ range nomadService "default-nomad-provider-service-primary" }}
|
|
service {{ .Name }} {{ .Tags }} {{ .Datacenter }} {{ .AllocID }}{{ end }}
|
|
EOH
|
|
|
|
destination = "${NOMAD_TASK_DIR}/service.conf"
|
|
change_mode = "noop"
|
|
}
|
|
}
|
|
}
|
|
}
|