[chef] Re: Re: How to add/modify the default template provided by cookbook but without editing the given template?


Chronological Thread 
  • From: Sachin Sagar Rai < >
  • To:
  • Subject: [chef] Re: Re: How to add/modify the default template provided by cookbook but without editing the given template?
  • Date: Sat, 11 Aug 2012 16:41:17 +0545

Thanks for the reply.

Yup, agreed on using the LWRP given by chef_handler cookbook.

But my question still remains that what if the third-party cookbook doesn't have the LWRP?


-------------------------------------------
@millisami
~ Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com
Sent with Sparrow

On Thursday, July 19, 2012 at 1:26 PM, Torben Knerr wrote:

Ohai!

maybe this is what you are looking for:

AFAICT the chef_handler LWRP takes care of managing your handlers. I don't know whether it would write through to the client.rb though. See the example here:
chef_gem "chef-handler-mail"
gem "chef-handler-mail"

chef_handler "MailHandler" do
   source 'chef/handler/mail'
   arguments :to_address => "root"
   action :nothing
end.run_action(:enable)

I guess you would have to create a separate cookbook (e.g. 'my-handlers') where you define the handlers as shown above in the default recipe.

HTH,
Torben

P.S.:  It would be cool if you could manage the handlers via a databag - has someone done this already? 


On Thu, Jul 19, 2012 at 7:30 AM, millisami r < " target="_blank"> > wrote:
Ohai chefs!

e.g.

Following is the snippet from the 'chef-client::config' recipe.

    template "#{node["chef_client"]["conf_dir"]}/client.rb" do
      source "client.rb.erb"
      owner "root"
      group root_group
      mode 0644
      variables :chef_node_name => chef_node_name
      notifies :create, "ruby_block[reload_client_config]"
    end

Its values can be overridden to customize it.
But what if I to edit the template itself or how to put the modified template in my cookbook to get rendered instead of editing the default template provided by the cookbook itself?

e.g.
 
Now I want to use  `https://github.com/kisoku/chef-handler-mail`.
For this to work beside downloading, uploading to chef-server and using in roles/other-recipes, I've to add

    #Using /etc/chef/config.rb

    require 'rubygems'
    require 'chef/handler/mail'

    mail_handler = MailHandler.new
    report_handlers << mail_handler
    exception_handlers << mail_handler

to the template itself.

Now how to just override the default template provided by chef-client at `templates/default/client.rb.erb` only with the additional chef-handler-mail code appended to it?


@millisami
~Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com






Archive powered by MHonArc 2.6.16.

§