{"id":8387,"date":"2022-12-01T03:14:00","date_gmt":"2022-12-01T03:14:00","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=8387"},"modified":"2022-12-23T05:44:52","modified_gmt":"2022-12-23T05:44:52","slug":"how-to-test-chef-recipes-cookbooks-on-your-workstation-with-vagrant-and-virtualbox-using-test-kitchen","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-test-chef-recipes-cookbooks-on-your-workstation-with-vagrant-and-virtualbox-using-test-kitchen\/","title":{"rendered":"Chef Tutorials: Test Kitchen &#8211; Example of kitchen.yml with VAGRANT and VirtualBox"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"685\" height=\"559\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/chef-test-kitchen-2-2.png\" alt=\"\" class=\"wp-image-32107\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/chef-test-kitchen-2-2.png 685w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/chef-test-kitchen-2-2-300x245.png 300w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"576\" height=\"696\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/image-3.png\" alt=\"\" class=\"wp-image-32108\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/image-3.png 576w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/image-3-248x300.png 248w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>How to test Chef recipes\/cookbooks on your workstation with VAGRANT and VirtualBox using Test Kitchen<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>Install Test Kitchen, VAGRANT and VirtualBox:<\/strong><\/p>\n\n\n\n<p>C<strong>hef Test Kitchen:<\/strong> Test Kitchen is a testing tool that can execute your CHEF recipes on one or more platforms in isolation. A driver plugin architecture is used which lets you run your recipes on various cloud providers and virtualization technologies.<br> $ gem install test-kitchen<\/p>\n\n\n\n<p><strong>Virtualbox:<\/strong> VirtualBox is powerful Cross-platform Virtualization Software for x86-based systems. \u201cCross-platform\u201d means that it can be installed on Windows, Linux, Mac OS X and Solaris x86 computers.<br> $ sudo apt-get install virtualbox<\/p>\n\n\n\n<p><strong>VAGRANT:<\/strong> VAGRANT not only creates virtual machines, it mainly automates the work of setting up development environment.<br> $ sudo apt-get install vagrant<\/p>\n\n\n\n<p><strong>Step 1 &#8211; <\/strong>You can create kitchen.yml file in the chef-repo directory (as shown below) or in specific cookbook directory.<br> $ kitchen init<\/p>\n\n\n\n<p><strong>Step 2 &#8211;  <\/strong>Add the below mentioned content to the kitchen.yml file, in this file you can configure basic details like driver name (vagrant or docker), provisioner, base OS image, memory and recipe name.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/e0d2a7a2a4fbf240c34d1a4fc47e6eb2.js\"><\/script>\n\n\n\n<p><strong>Step 3 &#8211;<\/strong> To create VAGRANT machine use below-mentioned command:<br> $ kitchen list<br> $ kitchen create<\/p>\n\n\n\n<p><strong>Step 4 &#8211; <\/strong>To execute recipe on the VAGRANT virtual machine, use the below-mentioned command:<br> $ kitchen converge<\/p>\n\n\n\n<p><strong>Step 5 &#8211; <\/strong>To login to the VAGRANT vm, use kitchen login command as shown below:<br> $ kitchen login<\/p>\n\n\n\n<p><strong>Step 6 &#8211; <\/strong>And after testing if you want to delete the setup i.e. vagrant vm, use the command mentioned-below:<br> $ kitchen destroy<\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_95991\"><iframe loading=\"lazy\"  id=\"_ytid_83408\"  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_95991\"  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>How to test Chef recipes\/cookbooks on your workstation with VAGRANT and VirtualBox using Test Kitchen Install Test Kitchen, VAGRANT and VirtualBox: Chef Test Kitchen: Test Kitchen is a testing tool&#8230; <\/p>\n","protected":false},"author":1,"featured_media":8719,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[88],"tags":[],"class_list":["post-8387","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chef"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8387","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=8387"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8387\/revisions"}],"predecessor-version":[{"id":32110,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8387\/revisions\/32110"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/8719"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=8387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=8387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=8387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}