This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Description
Description
I'm having a hard time understanding levant templating for my nomad job. Let's say I have a variable .shortJobNames (can be true of false). I want to construct my prometheus config out of local file template and replace blackbox exporter service name placeholder with the actual one for prometheus to use consul service mesh (can be "blackbox" if .shortJobNames or [[ .jobName ]]-blackbox-[[ .instanceName ]] if not)
So this:
template {
destination = "local/prometheus.yml"
data = <<EOH
[[fileContents "monitoring/templates/prometheus/config.yml" ]]
EOH
}
Turns into this:
template {
destination = "local/prometheus.yml"
data = <<EOH
[[fileContents "monitoring/templates/prometheus/config.yml" | replace "$BLACKBOXSERVICENAME" [[ if .shortJobNames ]][[ with $blackboxservicename := "blackbox" ]][[ else ]][[ with $blackboxservicename := [[ .jobName ]]-blackbox-[[ .instanceName ]] ]]
EOH
[[ end ]]
}
Also tried with variable, but could not find in docs how to construct such a string:
template {
destination = "local/prometheus.yml"
[[ if .shortJobNames ]]
[[ with $blackboxservicename := "blackbox" ]]
[[ else ]]
[[ with $blackboxservicename := ".jobName-blackbox-.instanceName" ]]
[[end]]
data = <<EOH
[[fileContents "monitoring/templates/prometheus/config.yml" | replace "$BLACKBOXSERVICENAME" $blackboxservicename ]]
EOH
}
UPD: I do not want to hardcode name in config and\or job itself to utilize DRY. I have multiple environments which are independantly deployed
Output of levant version: