2

I'd like to use a template in a Nomad job that has a string value that can be optionally overridden on a node basis, something like this:

job "foldingathome" {
...
  meta {
    foldingathome_power = coalesce(meta.foldingathome_power, "medium")
  }
  template {
    destination = "${NOMAD_ALLOC_DIR}/data/config.xml"
    data = <<EOT
<config>
  <power v='{{ env "meta.foldingathome_power" }}'/>
</config>
EOT
  }
}

Example Nomad client metadata:

client {
  ...
  meta {
    foldingathome_power = "light"
  }
}

This job-level meta stanza almost works, and uses the node's meta.foldingathome_power properly.

However, nodes that don't have this metadata key do not fallback to using "medium", and instead interpolate an empty string.

Has anyone come across a solution to this usecase?

hufman
  • 163
  • 1
  • 2
  • 6
  • 1
    Seem like you can delete the coalesce function and manipulate in the template data using go-template and or https://github.com/hashicorp/consul-template/blob/main/docs/templating-language.md, like using if else and contains function or using envOrDefault function – kholisrag Jul 29 '22 at 17:50
  • That worked perfectly! Thank you so much! `` – hufman Jul 31 '22 at 17:32

0 Answers0