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

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).


Berksfile and metadata.rb have different purposes to solve and comes into picture at different stages of cookbook life-cycle.

  1. Berksfile is for dependency management for cookbooks. Consider a case where my cookbook is using a community cookbook from chef supermarket. In this case, first I need to download that community cookbook from supermarket and upload it along with my own cookbook to chef server. Berksfile simplifies this workflow for you. With single command (berks install), it downloads all dependent cookbooks (and their dependent cookbooks -- transitive dependencies) from their respective sources (may be from git repository or from supermarket). With another single command berks upload it uploads all these cookbooks to chef server. You do not have to upload them individually with knife cookbook upload. Role of Berksfile in particular cookbooks life-cycle finishes here.

  2. metadata.rb is referred by chef-client while actually converging the node. It uses this file to download all the required cookbooks from chef server (assuming that these cookbooks are now available on chef server by using berkshelf or knife ) to the node to successfully complete the chef-client run.