consulconsul-template

consul template {{node}} default value no use?


My consul-template version:

# ./consul-template -v

consul-template v0.18.0-rc2 (652183d)

I try to use the template below to test node:

{{with node}}{{.Node.Node}} ({{.Node.Address}}){{range .Services}}
  {{.Service}} {{.Port}} ({{.Tags | join ","}}){{end}}
{{end}}

I run the shell:

./consul-template -log-level debug -once -consul-addr consul-agent:9500 -template "/home/data/consul/templates/test1.tmpl:/home/data/consul/results/test1"

But after that, test1 has no result. The output debug info looks like below and the shell waiting forever:

2017/01/19 03:17:29.283638 [INFO] consul-template v0.18.0-rc2 (652183d)
2017/01/19 03:17:29.283660 [INFO] (runner) creating new runner (dry: false, once: true)
2017/01/19 03:17:29.284061 [DEBUG] (runner) final config: {"Consul":{"Address":"consul-agent:9500","Auth":{"Enabled":false,"Username":"","Password":""},"Retry":{"Attempts":5,"Backoff":250000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"Token":""},"Dedup":{"Enabled":false,"MaxStale":2000000000,"Prefix":"consul-template/dedup/","TTL":15000000000},"Exec":{"Command":"","Enabled":false,"Env":{"Blacklist":null,"Custom":null,"Pristine":false,"Whitelist":null},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":0},"KillSignal":2,"LogLevel":"debug","MaxStale":2000000000,"PidFile":"","ReloadSignal":1,"Syslog":{"Enabled":false,"Facility":"LOCAL0"},"Templates":[{"Backup":false,"Command":"","CommandTimeout":30000000000,"Contents":"","Destination":"/home/data/consul/results/test1","Exec":{"Command":"","Enabled":false,"Env":{"Blacklist":[],"Custom":[],"Pristine":false,"Whitelist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":30000000000},"Perms":420,"Source":"/home/data/consul/templates/test1.tmpl","Wait":{"Enabled":false,"Min":0,"Max":0},"LeftDelim":"","RightDelim":""}],"Vault":{"Address":"","Enabled":false,"RenewToken":true,"Retry":{"Attempts":5,"Backoff":250000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":true,"Key":"","ServerName":"","Verify":true},"UnwrapToken":false},"Wait":{"Enabled":false,"Min":0,"Max":0}}
2017/01/19 03:17:29.284113 [INFO] (runner) creating watcher
2017/01/19 03:17:29.284311 [INFO] (runner) starting
2017/01/19 03:17:29.284334 [DEBUG] (runner) running initial templates
2017/01/19 03:17:29.284347 [INFO] (runner) initiating run
2017/01/19 03:17:29.284394 [DEBUG] (runner) checking template b0b0ddfdf27b9ee0b190f139850272f6
2017/01/19 03:17:29.284811 [DEBUG] (runner) was not watching 1 dependencies
2017/01/19 03:17:29.284847 [DEBUG] (watcher) adding catalog.node
2017/01/19 03:17:29.284869 [DEBUG] (runner) diffing and updating dependencies
2017/01/19 03:17:29.284886 [DEBUG] (runner) watching 1 dependencies
2017/01/19 03:17:29.288772 [INFO] (runner) initiating run
2017/01/19 03:17:29.288796 [DEBUG] (runner) checking template b0b0ddfdf27b9ee0b190f139850272f6
2017/01/19 03:17:29.289160 [DEBUG] (runner) missing data for 1 dependencies
2017/01/19 03:17:29.289183 [DEBUG] (runner) diffing and updating dependencies
2017/01/19 03:17:29.289197 [DEBUG] (runner) catalog.node(8c163f72e7ac) is still needed
2017/01/19 03:17:29.289210 [DEBUG] (runner) watching 1 dependencies

But if I change the template like this:

{{with node "8c163f72e7ac"}}{{.Node.Node}} ({{.Node.Address}}){{range .Services}}
  {{.Service}} {{.Port}} ({{.Tags | join ","}}){{end}}
{{end}}

It works fine! Why I must give the node name? In consul-template doc https://github.com/hashicorp/consul-template#node, it said

When called without any arguments then the node for the current agent is returned.

Any help?


Solution

  • It has been fixed by https://github.com/hashicorp/consul-template/pull/856, after I report an issue for this. Thanks!