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


Chronological Thread 
  • From: millisami r < >
  • To: chef < >
  • Subject: [chef] How to add/modify the default template provided by cookbook but without editing the given template?
  • Date: Thu, 19 Jul 2012 11:15:38 +0545

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.

§