4

Basically I have a couple cookbooks I've written, and currently they all have the same definition file copied on each. Obviously this is a bad situation, as it makes adding new cookbooks more difficult, and changing that definition file requires changing three or four other files to be exactly the same.

Is there a way that, if I have a separate cookbook who's purpose is to basically just contain that definition, I can import that definition file into the recipes that need it?

12

Take a look at metadata: depends it will tell Chef to include the cookbook in the run list for this cookbook, and thus you will have the definition available. Just leave the default cookbook empty and it won't do anything.

| improve this answer | |
  • Ah, I had seen that command, I thought it just told chef to send that cookbook along with the one that depends on it so it's recipes would be available, I didn't realize it would actually import the definitions as well. – Mediocre Gopher Jul 15 '11 at 16:24
  • Just tested it, definitely works (not that I doubted you :P) – Mediocre Gopher Jul 15 '11 at 16:51
  • Glad it works for ya! Its a shame the chef documentation is so sparse. I just recently figured that out myself. – Kyle Jul 15 '11 at 16:58
  • I updated the wiki page linked in your answer to clarify that other things from cookbooks create dependencies and should be specified. – jtimberman Jul 24 '11 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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