popularity
question
4

Sharing code, definitions and other helpers between cookbook repos

I’m writing a couple of cookbook repos and would like to share some recipes and helpers (like definitions/* of cookbooks) between them. As I understand from CHEF-2308 the file-by-file merging and shadowing feature of the site-cookbooks directory is deprecated.

What would a DRY and simple to understand approach to sharing cookbook code be?

I’m pushing my cookbooks with rsync and running them with chef-solo, so I’m not bound by what the current Chef server supports.

I’m thinking of something modular like the site-cookbooks was, so that it’d be clear what helpers are shared and what’s repo specific. I’m trying to avoid mixing them into one file/directory like ‘knife cookbook vendor’ does with its git branch and merge approach.

Cheers

 
Answers: 1
3

One nice way to accomplish this is to create a set of “library” type recipe’s that define the definitions, LWRP, and other shared resources.

Other recipe’s in which you wanted to do these things should do the following:

  1. Define the “library” recipe as a dependency in metadata.rb via the depends keyword: {code} depends “library-cookbook” {code}

  2. Use the include_recipe DSL function inside a recipe:

{code} include_recipe “library-cookbook” {code}

This will ensure that all of library-cookbook’s LWRPs, libraries, and definitions are available in the recipe that depends on them. I hope this helps.

Answered
Dec 22 '11 at 14:33