levant
levant copied to clipboard
function "runners" not defined error using nomad template to define gitlab-runner configuration file
Description
Defining a gitlab runner configuration file in the nomad template section can be confusing if the configuration file uses the same levant delimiter [[. Is there a better way to escape [[runners]] from evaluation otherwise I encounter the following error.
NOMAD_TOKEN=xxx VAULT_TOKEN=xxx levant deploy -var-file gitlab-runner.yml gitlab-runner.nomad
2020-10-22T21:16:23Z |DEBU| template/render: variable file extension .yml detected
2020-10-22T21:16:23Z |DEBU| template/render: no command line variables passed
[ERROR] levant/command: template: jobTemplate:78: function "runners" not defined
gitlab-runner.yml
---
env:
vault: ....
gitlab-runner.nomad
template {
env = false
destination = "${NOMAD_SECRETS_DIR}/config.toml"
data = <<EOH
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
url = "https://gitlab.com/"
token = "{{with secret "[[.env.vault]]"}}{{.Data.data.GITLAB_TOKEN}}{{end}}"
...
Output of levant version:
Levant v0.2.9
Date: 2019-12-27T09:43:30Z
Commit: 0f1913ea3d77584ddd0696da429dcf05572a73a0
Branch: 0.2.9
State: 0.2.9
Summary: 0f1913ea3d77584ddd0696da429dcf05572a73a0
Output of consul version:
Consul v1.8.0
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
Output of nomad version:
Nomad v0.12.1 (14a6893a250fc5f652eee4c7b52d8f95c3185aef)
runners.hack workaround
the following adulteration to get levant deploy -var-file gitlab-runner.yml gitlab-runner.nomad working
gitlab-runner.yml
---
+ runners:
+ hack: [[runners]]
env:
vault: ....
gitlab-runner.nomad
template {
env = false
destination = "${NOMAD_SECRETS_DIR}/config.toml"
data = <<EOH
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
- [[runners]]
+ [[.runners.hack]]
url = "https://gitlab.com/"
token = "{{with secret "[[.env.vault]]"}}{{.Data.data.GITLAB_TOKEN}}{{end}}"
...
The most idiomatic fix for this is to replace [[runners]] with [[ "[[runners]]" ]], which re-emits the string literal in place.