Stephen C
Stephen C

Reputation: 718926

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?

Upvotes: 3

Views: 3279

Answers (2)

Mark O'Connor
Mark O'Connor

Reputation: 77971

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.

Upvotes: 4

Stephen C
Stephen C

Reputation: 718926

To partly answer my own Question, one template can incorporate another using the Ruby "render" method. This is documented here: http://docs.opscode.com/resource_template.html#partial-templates

Upvotes: 0

Related Questions