Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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. An obvious solution since we are on git is to create a script that keeps them up to date, however just wondered if it is possible to have a single file/template referenced by multiple recipes/cookbooks. I thought about using symlinks, however this will not work as git does not support them.

Thanks!

share|improve this question

1 Answer 1

up vote 1 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
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"
end

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

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

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

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

 
discard

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.