{"id":353,"date":"2016-03-31T05:26:00","date_gmt":"2016-03-31T05:26:00","guid":{"rendered":"https:\/\/opstree.com\/blog\/\/2016\/03\/31\/chef-cookbooks-roast-it-perfectly\/"},"modified":"2025-11-24T15:48:47","modified_gmt":"2025-11-24T10:18:47","slug":"chef-cookbooks-roast-it-perfectly","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2016\/03\/31\/chef-cookbooks-roast-it-perfectly\/","title":{"rendered":"Chef-Cookbooks Roast it perfectly.."},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>&nbsp;<\/p>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 3pt; margin-top: 0; text-align: center;\"><span id=\"docs-internal-guid-ef960339-c7bc-e998-feb1-d1b734d7e179\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: center;\"><span id=\"docs-internal-guid-ef960339-c7bc-e998-feb1-d1b734d7e179\"><img loading=\"lazy\" decoding=\"async\" style=\"-webkit-transform: rotate(0.00rad); border: none; transform: rotate(0.00rad);\" src=\"https:\/\/lh3.googleusercontent.com\/a4p2t-xWWWr8nq_qMWzQlFBUTsxAq2G5kN_fkfXJjdBPNFutvhiyRQrjvMRx7N9l_KjD0w_Z6enK23vpbxx-4QYy2pc8gqhZv0N4nxzuWZsya0oQFnf92WMaA1a7bTpQM-N1JIm6\" width=\"494\" height=\"521\" \/><\/span><\/div>\n<h2 style=\"line-height: 1.38; margin-bottom: 6pt; margin-top: 18pt;\">Introduction<\/h2>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">This is our first major step towards our learnings. We are now quite sound with the ABC\u2019s of chef. Now we announce the most compelling facet of chef. Cookbooks are the most crucial segment of the chef\u2019s kingdom. Nothing worth having comes easy, so kickoff with more efforts.<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: center;\">\u201cA Real Test Of a Good Chef Is, Perfectly Roasted Chicken.\u201d<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: center;\"><strong>Julia Child<\/strong><\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">Wait wait wait !! fire your all cylinders but remember to breath.<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: center;\"><img loading=\"lazy\" decoding=\"async\" style=\"-webkit-transform: rotate(0.00rad); border: none; transform: rotate(0.00rad);\" src=\"https:\/\/lh4.googleusercontent.com\/CerBqDlMp6B5A2j0poJnOH8L70oerNlOLSfQdFNZLcID-m7GxvKroOh6Uwx7-ag3f8ZyS8ETjllAnUShFCOknxEWrDnW8BX3O-KDCwo0rMow4OjTLceLI1GEML1GfdlnBAlDy8cb\" width=\"452\" height=\"262\" \/><\/div>\n<h2 style=\"line-height: 1.38; margin-bottom: 6pt; margin-top: 18pt;\">Prerequisites<\/h2>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">This article assumes that you are aware with the basics of Git and Vagrant. You know the basic functioning of chef and its recipes and resources. This article is written with centos7 platform. To know about chef follow our previous blogs of this series Chef Start here with ease.. .<\/div>\n<h2 style=\"line-height: 1.38; margin-bottom: 6pt; margin-top: 18pt;\">Get started<\/h2>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>Clone our git repo and fire up a vagrant box with this.<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\">\n<p>$ git clone https:\/\/github.com\/OpsTree\/Chef.git<\/p>\n<\/div>\n<ul style=\"margin-bottom: 0; margin-top: 0;\">\n<li style=\"font-family: Arial; font-size: 14.6667px; list-style-type: disc; vertical-align: baseline;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: 14.6667px; vertical-align: baseline; white-space: pre-wrap;\">Go to Chef\/centos\/chefCookbooks directory. This directory contains a Vagrantfile, which can launch a centos7 vagrant machine with Chefdk and other essential tools installed.<br \/>\n<\/span><\/div>\n<\/li>\n<\/ul>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-left: 36pt; margin-top: 0; text-align: justify; text-indent: 36pt;\">\n<p>$ cat Vagrantfile<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-left: 72pt; margin-top: 0; text-align: justify;\">\n<p><img loading=\"lazy\" decoding=\"async\" style=\"-webkit-transform: rotate(0.00rad); border: none; transform: rotate(0.00rad);\" src=\"https:\/\/lh6.googleusercontent.com\/Ul29G4-v8S76y7hyP5I-C3gAG5DUSckYypPy_TbOb-Dw1DnRoYoVoXPCzCO_H579s8wCO-6nX4sNlnHNtjl2SCmC8_8u7Gnj9thuZ7pfgFX8dt0EhF6xODicRcCFnmYlV1S09YIF\" width=\"432\" height=\"108\" \/><\/p>\n<\/div>\n<ul style=\"margin-bottom: 0; margin-top: 0;\">\n<li style=\"font-family: Arial; font-size: 14.6667px; list-style-type: disc; vertical-align: baseline;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: 14.6667px; vertical-align: baseline; white-space: pre-wrap;\">Download Chefdk using below available command<br \/>\n<\/span><\/div>\n<\/li>\n<\/ul>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\">$ cd Chef\/centos\/chefCookbooks<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\">\n<p>$ wget https:\/\/opscode-omnibus-packages.s3.amazonaws.com\/el\/7\/x86_64\/chefdk-0.11.2-1.el7.x86_64.rpm<\/p>\n<\/div>\n<ul style=\"margin-bottom: 0; margin-top: 0;\">\n<li style=\"font-family: Arial; font-size: 14.6667px; list-style-type: disc; vertical-align: baseline;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: 14.6667px; vertical-align: baseline; white-space: pre-wrap;\">This directory also includes a knife.rb file which sets the cookbook folder path and default editor for the virtual machine.<\/span><\/div>\n<\/li>\n<li style=\"font-family: Arial; font-size: 14.6667px; list-style-type: disc; vertical-align: baseline;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: 14.6667px; vertical-align: baseline; white-space: pre-wrap;\">Launch a new vagrant machine and login into it.<br \/>\n<\/span><\/div>\n<\/li>\n<\/ul>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-left: 36pt; margin-top: 0; text-align: justify; text-indent: 36pt;\">\n<p>$ vagrant up<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-left: 36pt; margin-top: 0; text-align: justify; text-indent: 36pt;\">\n<p>$ vagrant ssh<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\">Your working environment is ready. Let&#8217;s start with chef cookbooks.<\/div>\n<h2 style=\"line-height: 1.38; margin-bottom: 6pt; margin-top: 18pt;\">Create your first cookbook<\/h2>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">First create a dedicated directory for our cookbooks. As in knife.rb file it will be created by following command.<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ mkdir \/vagrant\/cookbooks<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">Chef manage its cookbooks using a version control system so next we initialize and also make our first commit for \/vagrant\/cookbooks directory. Provide your name and email for git configuration.<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-indent: 36pt;\">$ mkdir \/vagrant\/cookbooks<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-indent: 36pt;\">$ cd \/vagrant\/cookbooks<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-indent: 36pt;\">$ git init<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-indent: 36pt;\">$ git add .<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-indent: 36pt;\">$ git config &#8211;global user.email &#8220;<a style=\"text-decoration: none;\" href=\"mailto:you@example.com\">you@example.com<\/a>&#8220;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-indent: 36pt;\">$ git config &#8211;global user.name &#8220;Your Name&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-indent: 36pt;\">$ git commit -m &#8220;Initial Commit&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">Now you are ready to start with the creation of your first cookbook.<\/div>\n<h3 style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 16pt;\">Call up with knife<\/h3>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">We are using knife to generate are cookbooks. Generate your cookbook for installing nginx and to set a virtual hosts opstree.com\/blog\/ and chef.opstree.com with this.<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">Generate our first cookbook using below written command. This command setup copyright, email, license, and readme format options for your cookbook.<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ knife cookbook create nginxVhost -C &#8220;Saurabh Vajpayee&#8221; -m &#8220;myemail@email.com&#8221; -I nginxv1 -r md<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\"><img loading=\"lazy\" decoding=\"async\" style=\"-webkit-transform: rotate(0.00rad); border: none; transform: rotate(0.00rad);\" src=\"https:\/\/lh4.googleusercontent.com\/Q05uud0NpGH_7y0UkVOAx6PQPZuCW4K8A6BBXEYFk--jfcXVBk_WQRhMn8ls3akgHOH0aTtQ1zzN5wSqYX1nj14lRhrsvkT6qjfhewdWmX08s65D-DJ_v4ibbhMvzerxlj7Oxk2I\" width=\"570\" height=\"98\" \/><\/div>\n<h3 style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 16pt;\">Let&#8217;s create a recipe<\/h3>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">Create the default recipe with below provided command and put below available content.<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>$ vim \/vagrant\/cookbooks\/nginxVhost\/recipes\/default.rb<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">package &#8216;epel-release&#8217; do<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">action :install<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>end<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">package &#8216;nginx&#8217; do<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">action :install<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>end<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">directory &#8220;#{node[&#8216;nginx&#8217;][&#8216;webroot&#8217;]}&#8221; do<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0recursive true<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>end<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">template &#8220;\/etc\/nginx\/conf.d\/#{node[&#8216;nginx&#8217;][&#8216;conffile&#8217;]}&#8221; do<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0source &#8216;chefmanagedconf.conf.erb&#8217;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0variables(<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0:port =&gt; &#8220;#{node[&#8216;nginx&#8217;][&#8216;port&#8217;]}&#8221;,<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0:servername =&gt; &#8220;#{node[&#8216;nginx&#8217;][&#8216;servername&#8217;]}&#8221;,<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0:webroot =&gt; &#8220;#{node[&#8216;nginx&#8217;][&#8216;webroot&#8217;]}&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0)<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>end<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">template &#8220;#{node[&#8216;nginx&#8217;][&#8216;webroot&#8217;]}\/index.html&#8221; do<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0source &#8216;index.html.erb&#8217;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0variables(<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0:servername =&gt; &#8220;#{node[&#8216;nginx&#8217;][&#8216;servername&#8217;]}&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0)<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>end<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">line = &#8220;127.0.0.1 #{node[&#8216;nginx&#8217;][&#8216;servername&#8217;]}&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">file = Chef::Util::FileEdit.new(&#8216;\/etc\/hosts&#8217;)<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">file.insert_line_if_no_match(\/#{line}\/, line)<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">file.write_file<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">service &#8216;iptables&#8217; do<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0action :stop<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>end<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">service &#8216;nginx&#8217; do<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">action :restart<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>end<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">This file includes multiple chef resources and some variable like &#8216;webroot&#8217;, conffile, port and servername. These variables have their default values under attribute directory and used in the templates which are next to create.<\/div>\n<h3 style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 16pt;\">Create attribute file<\/h3>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">This file contains the default value of your variables used in recipes. Create a default.rb file and place these values.<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ chef generate attribute \/vagrant\/cookbooks\/nginxVhost\/ default<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ vim \/vagrant\/cookbooks\/nginxVhost\/attributes\/default.rb<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">default[&#8216;nginx&#8217;][&#8216;port&#8217;] = &#8220;80&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">default[&#8216;nginx&#8217;][&#8216;webroot&#8217;] = &#8220;\/usr\/share\/nginx\/blog&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">default[&#8216;nginx&#8217;][&#8216;servername&#8217;] = &#8220;opstree.com\/blog\/&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">default[&#8216;nginx&#8217;][&#8216;conffile&#8217;] = &#8220;opstree.com\/blog\/.conf&#8221;<\/div>\n<h3 style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 16pt;\">Create templates<\/h3>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>Create template file to provide dynamic touch to your files. First create template for \u201cconfiguration\u201d files, and put below provided content.$ chef generate template \/vagrant\/cookbooks\/nginxVhost\/ chefmanagedconf.conf<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>$ vim \/vagrant\/cookbooks\/nginxVhost\/templates\/default\/chefmanagedconf.conf.erb<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">server<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">{<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0listen \u00a0\u00a0\u00a0\u00a0\u00a0 <i>&lt;%= @port \u00a0%&gt;<\/i>;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0server_name \u00a0;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0location \/ {<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0root \u00a0\u00a0;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0index \u00a0index.html index.htm;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0}<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0error_page \u00a0404 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/404.html;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0location = \/404.html {<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0root \u00a0\u00a0;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0}<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0# redirect server error pages to the static page \/50x.html<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0error_page \u00a0\u00a0500 502 503 504 \u00a0\/50x.html;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0location = \/50x.html {<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0root \u00a0\u00a0;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\u00a0\u00a0}<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>And next place template for index.html file with following content.<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>$ chef generate template \/vagrant\/cookbooks\/nginxVhost\/ index.html<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>$ vim \/vagrant\/cookbooks\/nginxVhost\/templates\/default\/index.html.erb<\/p>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p>&lt;!DOCTYPE html PUBLIC &#8220;-\/\/W3C\/\/DTD XHTML 1.1\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/xhtml11\/DTD\/xhtml11.dtd&#8221;&gt;<\/p>\n<p>&lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221; xml:lang=&#8221;en&#8221;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;Test Page for the Opstree Server &lt;\/title&gt;<br \/>\n&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<br \/>\n&lt;h1&gt;Welcome to &lt;strong&gt; &lt;%= @servername %&gt; &lt;\/strong&gt;&lt;\/h1&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>Your cookbook is ready for initial workings. Let\u2019s run it.<\/p>\n<\/div>\n<h2 style=\"line-height: 1.38; margin-bottom: 6pt; margin-top: 18pt;\">Run and feel like a million bucks<\/h2>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">Run your cookbook with below command, and relax for a while.<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ sudo chef-client &#8211;local-mode \u00a0&#8211;runlist &#8216;recipe[nginxVhost]&#8217;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">By default this cookbook setup opstree.com\/blog\/ vhost if you want to setup another vhost chef.opstree.com then overiride default values of variables. To do this create a json file which declares the new values for variables.<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ vim \/vagrant\/runlist.json<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">{<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">&#8220;nginxVhost&#8221;: {<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">&#8220;webroot&#8221; : &#8220;\/usr\/share\/nginx\/chef&#8221;,<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">&#8220;servername&#8221; : &#8220;chef.opstree.com&#8221;,<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">&#8220;conffile&#8221;: &#8220;chef.opstree.com.conf&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">},<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">&#8220;run_list&#8221;: [<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">&#8220;recipe[nginxVhost]&#8221;<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">]<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">}<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">And run chef-client once again with following commands.<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ sudo chef-client &#8211;local-mode \u00a0-j \/vagrant\/runlist.json<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">Now you \u00a0have power to create as many vhost automatically with chef.<\/div>\n<h3 style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 16pt;\">Verify the vhost<\/h3>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ curl opstree.com\/blog\/<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">$ curl chef.opstree.com<\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">From now we have to work hard to match the expectation of the industry. You are now developing into a chef proficient. Do some experiments and play hard.<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: center;\"><img loading=\"lazy\" decoding=\"async\" style=\"-webkit-transform: rotate(0.00rad); border: none; transform: rotate(0.00rad);\" src=\"https:\/\/lh3.googleusercontent.com\/BV6DYb_lwwsuRvyt884vOqrEA86svRc566rxKQnE1BiRMQfVCX1txap-Raf4YL_DutESF22EryoH72ccodeEJBvoBvjfB9EOtkcfbKmlVb7wskheBeNSgQPdQ7q3ADxJOY1MdHmF\" width=\"376\" height=\"152\" \/><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u00a0 Introduction This is our first major step towards our learnings. We are now quite sound with the ABC\u2019s of chef. Now we announce the most compelling facet of chef. Cookbooks are the most crucial segment of the chef\u2019s kingdom. Nothing worth having comes easy, so kickoff with more efforts. \u201cA Real Test Of &hellip; <a href=\"https:\/\/opstree.com\/blog\/2016\/03\/31\/chef-cookbooks-roast-it-perfectly\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Chef-Cookbooks Roast it perfectly..&#8221;<\/span><\/a><\/p>\n","protected":false},"author":72934568,"featured_media":29900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[225871,28070474],"tags":[768739297,768739308,676319247,101807,28382],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2025\/11\/DevSecOps-1.jpg","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-5H","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/353"}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/72934568"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=353"}],"version-history":[{"count":17,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/353\/revisions"}],"predecessor-version":[{"id":30050,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/353\/revisions\/30050"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/29900"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}