Created
March 23, 2020 19:29
-
-
Save Gurpartap/010b87b63f84b6c104566c758ff52199 to your computer and use it in GitHub Desktop.
nomad + consul template comma separated services from tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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