You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
You would want to use the printf function to concatenate the long form of your variable. The printf function is useful for generating composed values that can be arguments for functions like env and index as well.
Here's how I would do it. Note, the [[- and -]] are whitespace controlling delimiters and remove any non-explicitly generated whitespace outside of them. You can also solve for the variable very early in the template rendering so that you can use the built service name in other places as well.
A note about false(ish) values: the text/template library treats values that match go's floor values of a type as implicitly false. The .shortJobNames or .longJobNames, cases that you and I have as the target of the if are only false when unset or "". Any other value evaluates to true because the string is non-empty. If you are expecting the value to be populated, you should use the eq function and check it against a known value or convert it from string to boolean
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:
Turns into this:
Also tried with variable, but could not find in docs how to construct such a string:
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
:The text was updated successfully, but these errors were encountered: