Specify cookbook dependencies in metadata.rb or in Berksfile?


Just to confirm want check my understanding with community.

I have read that metadata.rb file tells chef-client when it's running which cookbooks should be downloaded from Chef server to the node.

While Berksfile tells to Berkshelf which dependencies should be downloaded to your local machine to .berkshelf directory from specified sources (internet, local paths, etc).

If it's right should i always specify dependencies in 2 files? Or is there a situations when i can/should specify dependencies only in one of them?


Hi @mpolitaev,

I think 99% of the time your Berksfile should look something like this:

source :chef_server
source 'https://supermarket.chef.io'


The first two lines list your sources (for me, my own chef server and the public supermarket) and the metadata line tells berks to read the list of cookbooks and version information from metadata.rb - so you can get by only specifying it there and don't have to write your list of dependencies in two places.


Dependencies in Berksfiles can be used in Kitchen which is very handy if you want some other cookbook in your run_list for testing. You can even specify a local fixture cookbook for testing.
But in general @ccrebolder is right...


Berksfile is not used by chef-client, at all. It's a reference to generate Berksfile.lock, which assembles a reference tree of the cookbooks and their requirements from Berksfile and metada.rb or metadata.json from the cookbooks listed there. Those cookbooks are, typically, then uploaded to the chef server or can be stored locally in an organized way with the "berks vault" commant. Berksfile is for building server configurations and providing a staging location to upload cookbooks to the server from.

Berksfile normally has nothing to do with the local run of chef-client. The chef server, or for chef-zero a local working directory, is polled for the relevant cookbooks requested by the run-list. Dependencies are assembled from that, at run-time, and those cookbooks downloaded or synchronized and used locally.