RE: Ohai Chefs! - Template writing issue

I apologize ahead of time for the subject line. I hit send before I should have :stuck_out_tongue:

Thanks,

Phillip Roberts | Sr. Linux Systems Administrator
MyBuyshttp://www.mybuys.com/ - Know Every Consumer
O 734.922.7014| M 614.423.9871 | proberts@mybuys.commailto:proberts@mybuys.com
@MyBuys | LinkedInhttp://www.linkedin.com/company/49603?trk=tyah&trkInfo=tarId%3A1395707807021%2Ctas%3Amybuys%2Cidx%3A3-1-5 | Facebookhttps://www.facebook.com/pages/MyBuys/145695757237?ref=br_tf

From: Phillip Roberts [mailto:proberts@mybuys.com]
Sent: Wednesday, July 23, 2014 1:08 PM
To: chef@lists.opscode.com
Subject: [chef] Ohai Chefs!

Is there a way to make a recipe only write a template file if the file doesn’t exist or if the template has changed?

For instance, I have a recipe that generates zone files for bind based off of a list of domains in a data bag. However, on every chef-client run, it is regenerating the file, which is also regenerating the serial number.

Any assistance would be appreciated.

Thanks,

Phillip Roberts | Sr. Linux Systems Administrator
MyBuyshttp://www.mybuys.com/ - Know Every Consumer
O 734.922.7014| M 614.423.9871 | proberts@mybuys.commailto:proberts@mybuys.com
@MyBuys | LinkedInhttp://www.linkedin.com/company/49603?trk=tyah&trkInfo=tarId%3A1395707807021%2Ctas%3Amybuys%2Cidx%3A3-1-5 | Facebookhttps://www.facebook.com/pages/MyBuys/145695757237?ref=br_tf

On Wednesday, July 23, 2014 at 10:09 AM, Phillip Roberts wrote:

Is there a way to make a recipe only write a template file if the file doesn’t exist or if the template has changed?

For instance, I have a recipe that generates zone files for bind based off of a list of domains in a data bag. However, on every chef-client run, it is regenerating the file, which is also regenerating the serial number.

Any assistance would be appreciated.

Thanks,

Phillip Roberts | Sr. Linux Systems Administrator

That’s how chef works now. Specifically, it renders the template to a tempfile and then compares the content with the existing file and makes a change if there’s a difference. I’d guess there’s something volatile in your template logic that produces logically equivalent files with different content. Chef should be showing you diffs of what changed, which should help make it more obvious what’s going on. Sharing the relevant portions of your templates would help us help you. Generally, you might need to sort some of your data to ensure a stable order before you loop over it in your templates.

--
Daniel DeLeo