Notification on template change

Hi list,

I’m searching for a way to notify another resource, as soon as a template changed:

template “foo.conf” do
source "foo.conf.erb"
notfies :run, "execute[rebuildConfig]"
end

(see this recipe [1]).

When using the create_if_missing action, it’s only created once, but not as soon as I upload a cookbook with a changed version of the config file.
With the create action, the resource is notified every time (which flushes caches, regenerates merged config files etc…).

Is there a way in between? Notify, if the old and the new file differ?

Thanks for your help!
Steffen

[1] https://github.com/StephenKing/chef-cookbook-otrs/blob/master/recipes/default.rb#L175

P.S: It would be great, if one wants to review the OTRS cookbook - it still has some minor issues (and probably misses some best-practices)

Hi Steffen,

usually the :create action is what you want; if the rendered content of the
template equals the content of the destination file, Chef should not
"recreate" the file (check for access timestamps), thus the notifies will
only be run when the content differs (i.e. you change an attribute that is
used in the template or change the template file itself).

At least that is what I was believing and hoping :slight_smile:

If this is not the case I either misunderstood a lot of my
services/cookbooks or my infrastructure should've gone to hell a long time
ago :slight_smile:

Regarding the OTRS cookbook, I'll let a coworker know, and also check it
out myself. My perl is pretty bad but my chef is decent (at least imo).

Have you considered writing an upgrade.rb recipe which would incrementally
update from a pretty old version to the most recent one or something like
this? If I understood it correctly OTRS offers no direct upgrade paths from
e.g. 2.2 => 3.0 but instead you have to install 2.3, then 2.4 and so on.

Cheers,

Oscar

On Mon, Feb 13, 2012 at 8:10 PM, Steffen Gebert st+opscode@st-g.de wrote:

Hi list,

I'm searching for a way to notify another resource, as soon as a template
changed:

template "foo.conf" do
source "foo.conf.erb"
notfies :run, "execute[rebuildConfig]"
end

(see this recipe [1]).

When using the create_if_missing action, it's only created once, but not
as soon as I upload a cookbook with a changed version of the config file.
With the create action, the resource is notified every time (which flushes
caches, regenerates merged config files etc..).

Is there a way in between? Notify, if the old and the new file differ?

Thanks for your help!
Steffen

[1]
chef-cookbook-otrs/recipes/default.rb at master · StephenKing/chef-cookbook-otrs · GitHub

P.S: It would be great, if one wants to review the OTRS cookbook - it
still has some minor issues (and probably misses some best-practices)

Hi Oscar,

thanks a lot for your response!

usually the :create action is what you want; if the rendered content of the template equals the content of the destination file, Chef should not "recreate" the file (check for access timestamps), thus the notifies will only be run when the content differs
Well.. that's what I would also expect.

After re-re-reading the output, I noticed that I created something like a perpetual motion: It is obviously bad to set (non-perfect) permissions for the config files via chef, which then itself triggers the run of OTRS' SetPermissions.pl - which then changes permissions back to something else. Of course, the same starts again during the next chef run :wink:
After setting the correct permissions in the recipe, everything works fine now, yay :slight_smile:

Have you considered writing an upgrade.rb recipe which would incrementally update from a pretty old version to the most recent one or something like this? If I understood it correctly OTRS offers no direct upgrade paths from e.g. 2.2 => 3.0 but instead you have to install 2.3, then 2.4 and so on.
No, I didn't consider it yet. I directly started my cookbook with OTRS 3.1 (which became stable today btw.).
IIRC you have to upgrade to 3.0 first and update scripts from 2.x (x <= 4) exist. But yes, you mustn't skip 3.0.

I would appreciate a contribution of such an upgrade recipe. I don't have any experience with that, yet, and have no personal need.

Thanks a lot for your help!
Steffen

On 14.02.2012, at 03:50, oscar schneider wrote:

Hi Steffen,

usually the :create action is what you want; if the rendered content of the template equals the content of the destination file, Chef should not "recreate" the file (check for access timestamps), thus the notifies will only be run when the content differs (i.e. you change an attribute that is used in the template or change the template file itself).

At least that is what I was believing and hoping :slight_smile:

If this is not the case I either misunderstood a lot of my services/cookbooks or my infrastructure should've gone to hell a long time ago :slight_smile:

Regarding the OTRS cookbook, I'll let a coworker know, and also check it out myself. My perl is pretty bad but my chef is decent (at least imo).

Have you considered writing an upgrade.rb recipe which would incrementally update from a pretty old version to the most recent one or something like this? If I understood it correctly OTRS offers no direct upgrade paths from e.g. 2.2 => 3.0 but instead you have to install 2.3, then 2.4 and so on.

Cheers,

Oscar

On Mon, Feb 13, 2012 at 8:10 PM, Steffen Gebert st+opscode@st-g.de wrote:
Hi list,

I'm searching for a way to notify another resource, as soon as a template changed:

template "foo.conf" do
source "foo.conf.erb"
notfies :run, "execute[rebuildConfig]"
end

(see this recipe [1]).

When using the create_if_missing action, it's only created once, but not as soon as I upload a cookbook with a changed version of the config file.
With the create action, the resource is notified every time (which flushes caches, regenerates merged config files etc..).

Is there a way in between? Notify, if the old and the new file differ?

Thanks for your help!
Steffen

[1] chef-cookbook-otrs/recipes/default.rb at master · StephenKing/chef-cookbook-otrs · GitHub

P.S: It would be great, if one wants to review the OTRS cookbook - it still has some minor issues (and probably misses some best-practices)