Search code examples
chef-infraberkshelfberksfile

Chef 'cookbook' in Berksfile vs 'depends' in metadata.rb


What's the difference between adding cookbooks to Berksfile using 'cookbook' and adding cookbooks to metadata.rb using 'depends'? For example, if I add to metadata.rb

depends 'nginx'

do I need to add it to Berksfile using

cookbook 'nginx'

?


Solution

  • The Berksfile is Berkshelf specific, while the metadata file is built into Chef.

    Adding your dependencies to the metadata file allows other applications, like librarian-chef or the supermarket, to read your dependencies as well.

    Note that Berkshelf reads the dependencies from metadata as well, as long as you add the metadata line to the Berksfile.

    I strongly recommend specifying all dependencies in your metadata file, and using your Berksfile to point to where specific cookbooks are stored if they're not available in the supermarket (like Github, or a local path).