Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'

?

like image 683
tokenvolt Avatar asked Aug 16 '14 18:08

tokenvolt


People also ask

What is metadata RB in Chef?

A file named metadata. rb is located at the top of every cookbook directory structure. The contents of the metadata. rb file provides hints to the Chef server to help ensure that cookbooks are deployed to each node correctly.

What is Berksfile in Chef?

Berksfile is the most crucial component of Berkshelf! It's just like metadata for Chef. However, the usage is somewhat different. Berksfile makes it simple to download a dependency cookbook from chef supermarket (or other places) and upload to the cookbook repository on the server.

How does Chef server and client communicate to get cookbook to configure the production server?

Chef Server The workstation sends the cookbook to the server using a knife. The nodes communicate with the server using the Chef client. If there are any changes made to the infrastructure code, they must be passed through the Chef Server to apply them to the nodes.

What is Chef cookbook and recipe?

Cookbooks are fundamental working units of Chef, which consists of all the details related to working units, having the capability to modify configuration and the state of any system configured as a node on Chef infrastructure. Cookbooks can perform multiple tasks.


2 Answers

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

like image 200
Nils Landt Avatar answered Sep 23 '22 11:09

Nils Landt


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.

like image 28
vinayakshnd Avatar answered Sep 19 '22 11:09

vinayakshnd