consul-template
, for all it's power, isn't the ideal handler for Consul Watches:
- In
-once
mode (I don't know how else you'd run it as a watch handler) it doesn't always actualy render the template. I'm sure the reasons for (sometimes) not doing so are good and make sense, but (to my knowledge) there isn't a way to tellconsul-template
"no, don't think about it, just render the template". - To my knowledge it has no way to read it's data directly from stdin, which is where Watches send their data to handlers.
- The added network call (because it can't render from the stdin-provided data) is both unnecessary, and a potential source of race conditions.
Note: If I'm wrong, and there is a way to make consul-template
behave simply and predictably and read from stdin, for the love of god, please email me and tell me how to do it.
You use it thusly in a consul watch config file:
{
"watches": [
{
"type": "service",
"service": "my-service",
"handler": "consul-watch-renderer path/to/template/file path/to/destination"
}
]
}
and that's it! If you must use it yourself on the command line (for testing a particular template perhaps), here's a way to do that:
$ consul-watch-renderer template destination < <(cat file.json)