{"id":4899,"date":"2018-04-17T09:36:21","date_gmt":"2018-04-17T09:36:21","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=4899"},"modified":"2021-11-17T10:36:32","modified_gmt":"2021-11-17T10:36:32","slug":"berkshelf-in-chef-explained","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/berkshelf-in-chef-explained\/","title":{"rendered":"Understanding the chef cookbook&#8217;s Berkshelf file"},"content":{"rendered":"<p>Configuration Management using chef is being implemented with the help of desire files, which is often called a &#8220;cookbooks&#8221; in chef. Usuallay separate cookbooks is written in practice for each module so its easy to maintain. Also, there are good numbers of cookbooks which is being used from community portal which is from supermarket.chef.io.<\/p>\n<p>In order to meet the desire state in servers, once the multile cookbooks is used, Very often these cookbooks become large and highly interdependent, it becomes necessary to manage these cookbooks itself.<\/p>\n<p>Berkshelf is the tool which makes \u2018the management\u2019 &amp; dependency management between cookbooks easy. Berkshelf is a dependency manager for Chef cookbooks. With it, you can easily depend on community cookbooks and have them safely included in your workflow. Using Berkshelf, you need to package, bundle dependent cookbooks rather using it will download from &#8220;source&#8221; which is defined in Berksfile.<\/p>\n<p>Berkshelf is included in the Chef Development Kit.<\/p>\n<p><strong>Quick Start<\/strong><br>\nRunning &#8220;<strong>chef generate cookbook<\/strong>&#8221; will, by default, create a Berksfile in the root of the cookbook, alongside the cookbook\u2019s metadata.rb. As usual, add your cookbook\u2019s dependencies to the metadata:<\/p>\n<p>[code]name &#8216;my_first_cookbook&#8217;<br>\nversion &#8216;0.1.0&#8217;<br>\ndepends &#8216;apt&#8217;, &#8216;~&gt; 5.0&#8242;[\/code]<\/p>\n<p>The default Berksfile will contain the following:<\/p>\n<p>[code]source &#8216;https:\/\/supermarket.chef.io&#8217;<br>\nmetadata[\/code]<\/p>\n<p>Now, when you run &#8220;<strong>berks install<\/strong>&#8220;, the apt cookbook will be downloaded from Supermarket into the cache&#8230;<\/p>\n<p>[code]$ berks install<br>\nResolving cookbook dependencies&#8230;<br>\nFetching &#8216;my_first_cookbook&#8217; from source at .<br>\nFetching cookbook index from https:\/\/supermarket.chef.io&#8230;<br>\nInstalling apt (5.0.0)<br>\nUsing my_first_cookbook (0.1.0) from source at .<br>\nInstalling compat_resource (12.16.2)[\/code]<\/p>\n<p><strong>Example of Berksfile<\/strong><\/p>\n<p>[code]source &#8220;https:\/\/supermarket.chef.io&#8221;<\/p>\n<p>metadata<br>\ncookbook &#8216;zabbix-agent&#8217;, path: &#8216;cookbooks\/zabbix-agent&#8217;<br>\ncookbook &#8216;hostnames&#8217;, path: &#8216;cookbooks\/hostnames&#8217;<br>\ncookbook &#8216;chef-client&#8217;, path: &#8216;cookbooks\/chef-client&#8217;<br>\ncookbook &#8216;rethinkdb&#8217;, path: &#8216;cookbooks\/rethinkdb&#8217;<br>\ncookbook &#8216;zookeeper&#8217;, path: &#8216;cookbooks\/zookeeper&#8217;<br>\ncookbook &#8216;logstash&#8217;, path: &#8216;cookbooks\/logstash&#8217;<br>\ncookbook &#8216;kafka&#8217;, path: &#8216;cookbooks\/kafka&#8217;<br>\ncookbook &#8216;elasticsearch&#8217;, path: &#8216;cookbooks\/elasticsearch&#8217;<br>\ncookbook &#8216;testbook&#8217;, path: &#8216;cookbooks\/testbook&#8217;<br>\ncookbook &#8216;base-ubuntu&#8217;, path: &#8216;cookbooks\/base-ubuntu'[\/code]<\/p>\n<p><strong>Important Notes<\/strong><br>\nFor new users, we strongly recommend using Policyfiles rather than Berkshelf. Policyfiles provide more predictability, since dependencies are only resolved once, and a much improved way of promoting cookbooks from dev to testing, and then to production. Note that Policyfile is not supported as part of a Chef Automate workflow.<\/p>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_89622\"><iframe loading=\"lazy\"  id=\"_ytid_84714\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_89622\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Configuration Management using chef is being implemented with the help of desire files, which is often called a &#8220;cookbooks&#8221; in chef. Usuallay separate cookbooks is written in practice for each&#8230; <\/p>\n","protected":false},"author":1,"featured_media":5120,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[88],"tags":[4896,4895],"class_list":["post-4899","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chef","tag-berksfile","tag-berkshelf"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=4899"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4899\/revisions"}],"predecessor-version":[{"id":25613,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4899\/revisions\/25613"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/5120"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=4899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=4899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=4899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}