tokenvolt
tokenvolt

Reputation: 1494

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'

?

Upvotes: 63

Views: 19355

Answers (3)

Anuj
Anuj

Reputation: 1

You don't need to declare dependencies in both of the files @Kamil Declare your dependencies in metadata.rb and source your local in house supermarket or chef supermaket in berksfile which will download dependencies for you.

Upvotes: 0

vinayakshnd
vinayakshnd

Reputation: 303

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.

Upvotes: 20

Nils Landt
Nils Landt

Reputation: 3134

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

Upvotes: 79

Related Questions