Template being updated every chef run

Hello,

I have a simple template like this

template “/etc/nagios3/conf.d/pagerduty_nagios.cfg” do
source "pagerduty_nagios.cfg.erb"
owner "nagios"
group "nagios"
mode 00644
variables(
:pager => pagerduty[“pager”]
)
notifies :restart, resources(:service => “nagios3”)
end

What happens it that the template its updated every time chef-client runs, and nagios is restarted
wich is bad, silly and annoying.
Chef claims the content, user and group changed. But it doesn’t. File checsum, user and group does
not change.
Here is the full chef-run[1]. User 104 is nagios user.

Help, because i am clueless why this happens

[1] http://paste.debian.net/199700/

Can you paste the entire template? If there's a Time.now or something
else that changes with each run it could cause it to be written every
time.

Sent from my iPhone

On Oct 12, 2012, at 7:33 PM, Alfredo Palhares masterkorp@masterkorp.net wrote:

Hello,

I have a simple template like this

template "/etc/nagios3/conf.d/pagerduty_nagios.cfg" do
source "pagerduty_nagios.cfg.erb"
owner "nagios"
group "nagios"
mode 00644
variables(
:pager => pagerduty["pager"]
)
notifies :restart, resources(:service => "nagios3")
end

What happens it that the template its updated every time chef-client runs, and nagios is restarted
wich is bad, silly and annoying.
Chef claims the content, user and group changed. But it doesn't. File checsum, user and group does
not change.
Here is the full chef-run[1]. User 104 is nagios user.

Help, because i am clueless why this happens

[1] http://paste.debian.net/199700/

I have ran into this same problem. I believe it is related to: http://tickets.opscode.com/browse/COOK-1460 not just pagerduty.

John

On Friday, October 12, 2012 at 4:32 PM, Alfredo Palhares wrote:

Hello,

I have a simple template like this

template "/etc/nagios3/conf.d/pagerduty_nagios.cfg" do
source "pagerduty_nagios.cfg.erb"
owner "nagios"
group "nagios"
mode 00644
variables(
:pager => pagerduty["pager"]
)
notifies :restart, resources(:service => "nagios3")
end

What happens it that the template its updated every time chef-client runs, and nagios is restarted
wich is bad, silly and annoying.
Chef claims the content, user and group changed. But it doesn't. File checsum, user and group does
not change.
Here is the full chef-run[1]. User 104 is nagios user.

Help, because i am clueless why this happens

[1] Debian paste error

On 10/12/2012 05:19 PM, John Dewey wrote:

I have ran into this same problem. I believe it is related
to: http://tickets.opscode.com/browse/COOK-1460 not just pagerduty.

I also ran into this problem. I changed the template slight, and it stopped
happening.

--
Phil Dibowitz phil@ipom.com
Open Source software and tech docs Insanity Palace of Metallica
http://www.phildev.net/ http://www.ipom.com/

"Be who you are and say what you feel, because those who mind don't matter
and those who matter don't mind."

  • Dr. Seuss

On 10/12/2012 06:04 PM, Phil Dibowitz wrote:

On 10/12/2012 05:19 PM, John Dewey wrote:

I have ran into this same problem. I believe it is related
to: http://tickets.opscode.com/browse/COOK-1460 not just pagerduty.

I also ran into this problem. I changed the template slight, and it stopped
happening.

Oh. I just remembered the case too.

I had JSON and I changed from:

...
}<% if whatever %>,
...
}<$ end %>

To:
<% if whatever %>
},
...
<% end %>
}

The first one make the template code think something had changed everytime...
not sure why, but the change is functionally equivalent, looks nicer, and
didn't trigger whatever crazy bug it was. I need to go back and try to come up
with a good repro.

--
Phil Dibowitz phil@ipom.com
Open Source software and tech docs Insanity Palace of Metallica
http://www.phildev.net/ http://www.ipom.com/

"Be who you are and say what you feel, because those who mind don't matter
and those who matter don't mind."

  • Dr. Seuss

Excerpts from Daniel Condomitti's message of Sat Oct 13 01:53:47 +0200 2012:

Can you paste the entire template? If there's a Time.now or something
else that changes with each run it could cause it to be written every
time.
No there isn't. Here is the template[1]

I am even more clueless now

[1] http://pastie.org/private/aaii2oyxr0cpp6rxtxnbsw

--
Regards,
Alfredo Palhares

Can you also paste the recipe? Specifically the variables block that's setting @pager. If you're just passing an object (other than a string) its ID would be changing each time (which may be detected as a change in the template to be outputted, I'm not sure how it determines if it has changed) but results in the same output since it's just calling .to_s on it.

On Monday, October 15, 2012 at 8:01 AM, Alfredo Palhares wrote:

Excerpts from Daniel Condomitti's message of Sat Oct 13 01:53:47 +0200 2012:

Can you paste the entire template? If there's a Time.now or something
else that changes with each run it could cause it to be written every
time.

No there isn't. Here is the template[1]

I am even more clueless now

[1] http://pastie.org/private/aaii2oyxr0cpp6rxtxnbsw

--
Regards,
Alfredo Palhares

Excerpts from Daniel Condomitti's message of Mon Oct 15 16:31:05 +0200 2012:

Can you also paste the recipe? Specifically the variables block that's setting @pager. If you're just passing an object (other than a string) its ID would be changing each time (which may be detected as a change in the template to be outputted, I'm not sure how it determines if it has changed) but results in the same output since it's just calling .to_s on it.
That actually makes sense, but i tried to just hardcode the strings, and even just placing it on the
template so it never changes. Still happens.

On Monday, October 15, 2012 at 8:28 AM, Alfredo Palhares wrote:

Excerpts from Daniel Condomitti's message of Mon Oct 15 16:31:05 +0200 2012:

Can you also paste the recipe? Specifically the variables block that's setting @pager. If you're just passing an object (other than a string) its ID would be changing each time (which may be detected as a change in the template to be outputted, I'm not sure how it determines if it has changed) but results in the same output since it's just calling .to_s on it.

That actually makes sense, but i tried to just hardcode the strings, and even just placing it on the
template so it never changes. Still happens.

Do you have another resource in your chef run or external process that is changing the file?

If you create a ruby_block resource to puts %x{ls -halp file} before your template resource, does it say what you expect?

Also, if you use Chef 10.14, you can run with -Fdoc -lfatal and you should see a content diff.

--
Daniel DeLeo

I’ve had issues in the past with searches that return nodes. The list of nodes won’t come back in the same order every time and the template will write out on every run. You want to make sure to sort any array of hostnames returned by search.

From: Daniel DeLeo <dan@kallistec.commailto:dan@kallistec.com>
Reply-To: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Date: Monday, October 15, 2012 9:01 AM
To: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Subject: [chef] Re: Re: Re: Re: Re: Template being updated every chef run

On Monday, October 15, 2012 at 8:28 AM, Alfredo Palhares wrote:

Excerpts from Daniel Condomitti’s message of Mon Oct 15 16:31:05 +0200 2012:
Can you also paste the recipe? Specifically the variables block that’s setting @pager. If you’re just passing an object (other than a string) its ID would be changing each time (which may be detected as a change in the template to be outputted, I’m not sure how it determines if it has changed) but results in the same output since it’s just calling .to_s on it.
That actually makes sense, but i tried to just hardcode the strings, and even just placing it on the
template so it never changes. Still happens.
Do you have another resource in your chef run or external process that is changing the file?

If you create a ruby_block resource to puts %x{ls -halp file} before your template resource, does it say what you expect?

Also, if you use Chef 10.14, you can run with -Fdoc -lfatal and you should see a content diff.


Daniel DeLeo

This is a ruby thing and not a Chef thing per se. Until 1.9 ruby hash
objects, for instance, did not preserve insert order. While I've
rarely run into this edge case inside Chef, if you think it's going to
be an issue you can perform sorting yourself on the result. I'm not
sure if Chef's search support allows solr ordering off the top of my
head.

I would highly suspect, however, that this is not the case here. I
would consider REALLY pouring over the logs and seeing if something
else is changing the file earlier in the recipe. I just ran into this
recently where I had one recipe changing a files permissions
(incorrectly as a side effect of a different operation) and another
recipe changing them BACK. The end result was the file had the proper
permissions but the issue was that they were being undone earlier in
the run.

It's also possible there's an edge case somewhere where a file or
template operation isn't atomic but again I'd go for the previous
explanation of something ELSE changing it earlier in the run.

On Mon, Oct 15, 2012 at 12:09 PM, Tim Smith Tim.Smith@webtrends.com wrote:

I've had issues in the past with searches that return nodes. The list of
nodes won't come back in the same order every time and the template will
write out on every run. You want to make sure to sort any array of
hostnames returned by search.

From: Daniel DeLeo dan@kallistec.com
Reply-To: "chef@lists.opscode.com" chef@lists.opscode.com
Date: Monday, October 15, 2012 9:01 AM
To: "chef@lists.opscode.com" chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: Re: Template being updated every chef run

On Monday, October 15, 2012 at 8:28 AM, Alfredo Palhares wrote:

Excerpts from Daniel Condomitti's message of Mon Oct 15 16:31:05 +0200 2012:

Can you also paste the recipe? Specifically the variables block that's
setting @pager. If you're just passing an object (other than a string) its
ID would be changing each time (which may be detected as a change in the
template to be outputted, I'm not sure how it determines if it has changed)
but results in the same output since it's just calling .to_s on it.

That actually makes sense, but i tried to just hardcode the strings, and
even just placing it on the
template so it never changes. Still happens.

Do you have another resource in your chef run or external process that is
changing the file?

If you create a ruby_block resource to puts %x{ls -halp file} before your
template resource, does it say what you expect?

Also, if you use Chef 10.14, you can run with -Fdoc -lfatal and you should
see a content diff.

--
Daniel DeLeo

Nope, that was my first tough, and no, nothing changes it.

After playing shef a bit i found this[1]

[2012-10-15T12:15:17-04:00] DEBUG: Current content’s checksum:

Aparently ruby is not reading that file properly. I am pretty sure this is not a system/permissions
problem.

Any ideas/sugestions are welcome.

[1] http://pastie.org/5067287

Can you provide the content of the recipe thats generating this
template ? That output suggest as you say that its not able to read
the current_resource.

On Tue, Oct 16, 2012 at 4:52 AM, Alfredo Palhares
masterkorp@masterkorp.net wrote:

Nope, that was my first tough, and no, nothing changes it.

After playing shef a bit i found this[1]

[2012-10-15T12:15:17-04:00] DEBUG: Current content's checksum:

Aparently ruby is not reading that file properly. I am pretty sure this is not a system/permissions
problem.

Any ideas/sugestions are welcome.

[1] http://pastie.org/5067287