chef-infrachef-template

Combining two templates from two Chef cookbooks


I have a cookbook for installing a base product (Mediaflux), and a second cookbook that tailors it for a particular specialised use-case (DaRIS). The first cookbook's recipe is run to do the "base install" and the second one's recipe is run to "tailor" the installation.

At one point, I have a file created by the base cookbook/recipe that needs extra stuff to be added in the second cookbook/recipe. In both cases, template expansion is required for this file.

I'm trying to figure out a good way to implement this.

Ideally, I'd like to be able to do one of the following:

Is there any way to do any of these things?

Is there another approach that I've missed?


Solution

  • The chef documentation describes the optional "cookbook" attribute that enables you to specify from where the template should be retrieved:

    template "/path/to/this/file" do
      source "file.erb"
      cookbook "myothercookbook"
      mode 0440
      owner "me"
      group "me"
      variables({
         :var1 => node[:mycurrentcookbook][:var1],
         :var2 => node[:mycurrentcookbook][:var2]
      })
    end
    

    This enables common templates to be re-used.