Hi,
We've started to use template in nomad to get our configuration from Consul but our Consul cluster is protected with ACL.
Is there a way to pass the Consul token in job configuration? (If no, I will create a github issue)
I tried to fill the environment variable CONSUL_HTTP_TOKEN in "env" section but it doesn't seems to be pass to consul-template by nomad agent.
So Nomad believes that Consul key is not present and the job remains in pending state.
Thanks for your help!
Cyril.
Test job:
job "template-test" {
datacenters = ["dc1"]
type = "batch"
group "template-test" {
task "template-test" {
driver = "exec"
config {
command = "sh"
args = ["-c", "sleep 5; cat local/test.conf; exit 0"]
}
template {
destination = "local/test.conf"
data = "{{ key \"configtest\" }}"
}
# Try to pass Consul token as an environment variable.
env {
CONSUL_HTTP_TOKEN = "test-token"
}
}
}
}
Server log below:
2017/01/17 10:17:56.110735 [DEBUG] client: starting task runners for alloc '47847e8c-f805-ca4b-e981-3ae38777e036'
2017/01/17 10:17:56.110867 [DEBUG] client: starting task context for 'template-test' (alloc '47847e8c-f805-ca4b-e981-3ae38777e036')
2017/01/17 10:17:56 [INFO] (runner) creating new runner (dry: false, once: false)
2017/01/17 10:17:56 [DEBUG] (runner) final config (tokens suppressed):
{
"Path": "",
"Consul": "",
"Token": "",
"ReloadSignal": 1,
"DumpSignal": 3,
"KillSignal": 2,
"Auth": {
"Enabled": false,
"Username": "",
"Password": ""
},
"Vault": {
"Address": "",
"UnwrapToken": false,
"RenewToken": false,
"SSL": {
"Enabled": true,
"Verify": true,
"Cert": "",
"Key": "",
"CaCert": "",
"CaPath": "",
"ServerName": ""
}
},
"SSL": {
"Enabled": false,
"Verify": true,
"Cert": "",
"Key": "",
"CaCert": "",
"CaPath": "",
"ServerName": ""
},
"Syslog": {
"Enabled": false,
"Facility": "LOCAL0"
},
"Exec": {
"Command": "",
"Splay": 0,
"ReloadSignal": null,
"KillSignal": 15,
"KillTimeout": 30000000000
},
"MaxStale": 1000000000,
"ConfigTemplates": [
{
"Source": "",
"Destination": "/tmp/nomad/alloc/47847e8c-f805-ca4b-e981-3ae38777e036/template-test/local/test.conf",
"EmbeddedTemplate": "{{ key \"configtest\" }}",
"Command": "",
"CommandTimeout": 0,
"Perms": 420,
"Backup": false,
"LeftDelim": "",
"RightDelim": "",
"Wait": {
"min": 0,
"max": 0
}
}
],
"Retry": 5000000000,
"Wait": {
"min": 0,
"max": 0
},
"PidFile": "",
"LogLevel": "WARN",
"Deduplicate": {
"Enabled": false,
"Prefix": "consul-template/dedup/",
"TTL": 15000000000
}
}
2017/01/17 10:17:56 [INFO] (clients) creating consul/api client
2017/01/17 10:17:56 [INFO] (clients) creating vault/api client
2017/01/17 10:17:56 [DEBUG] (clients) enabling vault SSL
2017/01/17 10:17:56 [INFO] (runner) creating Watcher
2017/01/17 10:17:56 [INFO] (runner) starting
2017/01/17 10:17:56 [DEBUG] (runner) running initial templates
2017/01/17 10:17:56 [INFO] (runner) running
2017/01/17 10:17:56 [DEBUG] (runner) checking template a7c72e8af6bd3ec74e72f63455032e62
2017/01/17 10:17:56 [INFO] (runner) was not watching 2 dependencies
2017/01/17 10:17:56 [INFO] (watcher) adding "key(configtest)"
2017/01/17 10:17:56 [DEBUG] (watcher) "key(configtest)" starting
2017/01/17 10:17:56 [INFO] (watcher) adding "key(configtest)"
2017/01/17 10:17:56 [DEBUG] (watcher) "key(configtest)" already exists, skipping
2017/01/17 10:17:56 [INFO] (runner) diffing and updating dependencies
2017/01/17 10:17:56 [INFO] (runner) watching 1 dependencies
2017/01/17 10:17:56 [DEBUG] (view) "key(configtest)" starting fetch
2017/01/17 10:17:56 [DEBUG] ("key(configtest)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:0 WaitTime:1m0s Token: Near:}
2017/01/17 10:17:56 [DEBUG](view) "key(configtest)" data was not present
2017/01/17 10:17:56 [DEBUG] ("key(configtest)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:9679 WaitTime:1m0s Token: Near:}