Replacing a template in a wrapper cookbook
As an alternative to Dave's answer, you can also use chef-rewind
.
https://github.com/bryanwb/chef-rewind
A quick usage example from the github repo
# file postgresql/recipes/server.rb
template "/var/pgsql/data/postgresql.conf" do
source "postgresql.conf.erb"
owner "postgres"
end
# file my-postgresql/recipes/server.rb
chef_gem "chef-rewind"
require 'chef/rewind'
include_recipe "postgresql::server"
# my-postgresql.conf.erb located inside my-postgresql/templates/default/my-postgresql.conf.erb
rewind :template => "/var/pgsql/data/postgresql.conf" do
source "my-postgresql.conf.erb"
cookbook_name "my-postgresql"
end
Making your patches and merging with upstream is the recommended practice when using knife
because knife does some of the git branch merging stuff automatically for you and you are able to keep track of what you initially changed.
Simply overwriting files in your wrapper cookbook is a practice I did not encounter earlier but looks interesting ^^ Disadvantage: you have to maintain and merge upstream changes into your modified template manually and that may be sometimes more work than letting git do most of the stuff for you.
Third way: rely on "cookbook shadowing" (deprecated) that works when you have direct control over which cookbooks will the end user will use: http://tickets.opscode.com/browse/CHEF-2308
You're pretty close. Assuming you have a modified version of the storage-schemas.conf.erb file in your wrapper cookbook, you can just do:
include_recipe "graphite"
begin
r = resources(:template => "#{node['graphite']['base_dir']}/conf/storage-schemas.conf")
r.cookbook "my-cookbook"
rescue Chef::Exceptions::ResourceNotFound
Chef::Log.warn "could not find template to override!"
end
You can also use a line like:
r.source "graphite-stuff/my-storage-schemas.conf.erb"
if you want to organize the files in your wrapper cookbook in a different way.