Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing a template in a wrapper cookbook

Tags:

I'm trying to write a wrapper cookbook for the chef graphite repo

In the recipe carbon.rb, the following lines occur:

template "#{node['graphite']['base_dir']}/conf/storage-schemas.conf" do   owner node['apache']['user']   group node['apache']['group'] end 

where in templates/default/storage-schemas.conf there is a storage-schemas.conf file that is not to my liking. I can edit the file inline and achieve what I want, but it doesn't seem like a good chef practice if I want to be able to keep my repo up to date without merge conflicts. So I was wondering if I could solve this with a wrapper cookbook.

My first though was something like

include_recipe "graphite" template "#{node['graphite']['base_dir']}/conf/storage-schemas.conf" do   owner node['apache']['user']   group node['apache']['group'] end 

where I would just rerun the command after the base recipe finished and put the file I wanted in wrappercookbook/templates/storage-schemas.conf.erb. Is this a common practice? It doesn't feel very DRY, but I can't think of a cleaner way.

like image 686
newmanne Avatar asked Apr 10 '13 18:04

newmanne


People also ask

What is wrapper cookbook?

What is a Wrapper Cookbook? Simply put, a wrapper cookbook is just a regular cookbook that includes recipes from other cookbooks. Common use cases for wrapper cookbooks include: Modifying the behavior of a community cookbook from the Chef Supermarket.

What is a template in chef?

Chef uses templates to be able to fill the configuration file with dynamic values. Chef provides templates as a resource which can be used in the recipe. Configuration files' dynamic values can be retrieved from data bags, attributes or even calculate them by passing them into the template.


1 Answers

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.

like image 99
Dave S. Avatar answered Oct 04 '22 21:10

Dave S.