0
votes

Understanding of "Metadata" keyword in berks file. Document Referred: https://docs.chef.io/berkshelf.html

The metadata keyword causes Berkshelf to process the local cookbook metadata. This ensures that the dependencies of the cookbook are resolved by Berkshelf. Using the metadata keyword requires that the Berksfile be placed in the root of the cookbook, next to metadata.rb.

Couldn't get what it means by Berkshelf file should be placed in root of cookbook. Should I create a file called Berkshelf, and place it in the same place where "metadata.rb" is added to cookbook (all cookbooks) and is made available via artifactory? I created a Berkshelf file in the VM where I'm installing the cookbooks, added metadata keyword. But getting error "Could not open or read: '/root/.chef/metadata.rb'"

Assuming that Berkfiles has to be added to each cookbook, would it contain "source" element? Because it would be added in the VM berksfile representing the cookbook location. I don't want to constrain the source in artifactory repo => the only text that the Berksfile would have is "metadata" in my case when it is added to each cookbook.

Goal: Is to resolve dependencies of each cookbook that are referred. NOTE: Even withouth "metadata" I observed that berks vendor command tried to download all referred cookboooks. Not sure how it is possible without any metadata keyword in the Berksfile created in VM where cookbook is installed

1

1 Answers

1
votes

It means you should have a file named "Berksfile" next to metadata.rb in your cookbook directory/repository.

"metadata" keyword means it will add to its list the dependencies referred in metadata.rb, allowing you to not repeat yourself. Most of the time, your cookbook's Berksfiles will only contain:

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

Here is an example of simple cookbook with such Berkfile: https://gitlab.com/chef-platform/test-cookbook.

If it contains more entries, it may be because you have a "test" dependency, that is, not referenced in cookbook metadata.

Here one cookbook with test dependencies: https://gitlab.com/chef-platform/confluent-platform.