Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have multiple cookbooks which reference the same files and templates and were wondering if there is a reasonable way to ensure all of these are the same file to ensure that none go out of date. Is it possible to have a single file/template referenced by multiple recipes/cookbooks? I thought about using symlinks, however this will not work for us as Git does not support them.

share|improve this question
up vote 10 down vote accepted

The cookbook_file and template resources support a "cookbook" parameter that specifies which cookbook contains the source file. Then you could create a "commons" cookbook where those files live as a single entity. For example:

% cookbooks/commons
|-- files
|   `-- default
|       `-- master.conf
`-- templates
    `-- default
        `-- general.conf.erb

Suppose you have two cookbooks, thing1 and thing2, and they both use these. The recipes might be:

# thing1/recipes/default.rb
cookbook_file "/etc/thing1/master.conf" do
  source "master.conf"
  cookbook "commons"

template "/etc/thing1/general.conf" do
  source "general.conf.erb"
  cookbook "commons"

# thing2/recipes/default.rb
cookbook_file "/etc/thing2/like_master_but_different.conf" do
  source "master.conf"
  cookbook "commons"

template "/etc/thing2/not_as_general_as_you_think.conf" do
  source "general.conf.erb"
  cookbook "commons"

However, I would ask why do you have duplication between different kinds of functionality in your cookbooks? That is, would this kind of thing be suitable for a custom lightweight resource/provider that you use?

share|improve this answer
Thank you for the example as well as the other solution. This is perfect! – gdurham Aug 10 '12 at 19:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.