Consul template remove watch from files

I have a consul template template and see that the output file is also being watched for changes. Is it possible to remove the watch placed on the output file.

Hey niteshthakur, thanks for asking.

Consul template currently uses the rendered template for testing whether it needs to update it or not. When consul-template gets data from consul/vault/etc. it renders the template in memory using that data and compares it vs. the one on the filesystem, updating the filesystem one if they are different. This is how it knows to update the file and cannot be disabled (pretty sure this is what you’re talking about).

If you need post rendering changes you might be able to use the template.exec for that template to run a script to copy it before making the changes? Keeping the original for the comparison.

Hope this helps.

hi eikenb, I was talking about changes being made directly to the rendered file on the disk. I see that if this file is changed, then consul issues a reload signal which I think is not correct.

I have a question related to exec part as well. Is the command guaranteed to be executed every time a template rendering occurs(due to a change)

Consul-template compares an in-memory rendered version of the template to the one on disk. So if you change the one on disk it will be different than the one rendered in memory and trigger a reload even if the data is the same.

It should occur every time new/differing data come in for the values in the template. That will trigger a render, which compares the in memory rendering to the on disk version and , if different, updates the on-disk version and reloads the application. If it doesn’t work this way it is probably a bug.

Hope this answers your questions better. Please feel free to ask any additional clarifying or new questions. Thanks.

What if there is a case where some other process is changing the rendered file and it is not desired that this change causes any reload. I think its reasonable to expect that only a kv change causes a change in the file and a reload. There should be an option to not place a watch on the rendered file(looks like this is how it is implemented) and just look for changes in kv.

Sorry but there is currently there is no option to disable this behavior as it is how consul-template knows to update the file. It has no other way of knowing when things have been changed.