Consul Template - yenbohuang/techNotes GitHub Wiki

References

Run consul-template

Command

Continuously:

# consul-template -consul=<Consul server IP>:8500 -config=consul-template.cfg

Run only once:

# consul-template -once -consul=<Consul server IP>:8500 -config=consul-template.cfg

Config

{
  retry = "10s"
  max_stale = "10m"
  log_level = "info"
  pid_file = "/home/yenbo.huang/tmp/consul-template.pid"
  template {
     source = "/home/yenbo.huang/consul-demo/config/demo.ctmpl"
     destination = "/home/yenbo.huang/tmp/demo.config.json"
     command_timeout = "30s"
     perms = 0644
     backup = true
}

Template

Although toJSONPretty should be considered final according to consul-template, it is very convenient for JSON format. We can fall back to the hard way (a complex template file) if it doesn't fulfill out requirements.

{{ tree "some/key-value/path" | explode | toJSONPretty }}