Hi,
I’m looking for a Nomad-native (i.e. without Consul or Terraform) way to pass snippets of config between jobs, which can then be interpreted by the template
block to have Nomad service discovery variables filled in.
I’ve tried declaring them as a local variable using heredoc formatting and then assigning the variable to a tag on the source job. The target job can then see the tag and pull it into it’s own template block, but any variables in the transferred code snippet don’t get interpolated as the templating process only makes one pass of the template.
source job:
locals {
snippet = <<EOH
snippet=some custom per-job config here (can not be templated) {
reverse_proxy {{ range nomadService "source-job" }}{{ .Address }}:{{ .Port }} {{ end }}
}
some more custom per-job config here
EOH
...
job "source-job"
group "test" {
task "test" {
tags = [ local.snippet ]
target job
template {
data = <<EOH
{{ range $tag, $services := nomadServices | byTag }}
{{ range $services }}
{{ if in $tag "snippet=" }}
{{- $tag | trimPrefix "snippet=" }}
{{ end }}
{{ end }}
{{ end }}
template renders as
some custom per-job config here (can not be templated) {
reverse_proxy {{ range nomadService "source-job" }}{{ .Address }}:{{ .Port }} {{ end }}
}
some more custom per-job config here
rather than
some custom per-job config here (can not be templated) {
reverse_proxy 192.168.1.1:80 192.168.1.3:80
}
some more custom per-job config here
Is there a way to make this work or a simpler way to do this that i’ve missed? I’m trying to do this to combine config from multiple source jobs, but the snippet is too complex and varied between each source job to have a standardised template.