Skip to content

Instantly share code, notes, and snippets.

@Gurpartap
Created March 23, 2020 19:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gurpartap/010b87b63f84b6c104566c758ff52199 to your computer and use it in GitHub Desktop.
Save Gurpartap/010b87b63f84b6c104566c758ff52199 to your computer and use it in GitHub Desktop.
nomad + consul template comma separated services from tags
job web {
datacenters = ["dc1"]
type = "service"
priority = 70
group app {
count = 1
task env {
driver = "exec"
config {
command = "/usr/bin/env"
}
template {
env = true
destination = "${NOMAD_SECRETS_DIR}/env"
data = <<EOF
SERVICES_FROM_TAG={{range services}}{{if in .Tags "tag-name-goes-here"}}{{$services:=service .Name "any"}}{{if gt (len $services) 0}}{{range $services}}{{.Address}}:{{.Port}},{{end}}{{end}}{{end}}{{end}}
EOF
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment