{"id":30941,"date":"2016-01-09T18:20:18","date_gmt":"2016-01-09T12:50:18","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=30941"},"modified":"2016-01-19T13:25:15","modified_gmt":"2016-01-19T07:55:15","slug":"chef-test-kitchen-how-to-test-chef-recipes-on-your-workstation","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/chef-test-kitchen-how-to-test-chef-recipes-on-your-workstation\/","title":{"rendered":"CHEF Test Kitchen: How to test CHEF recipes on your workstation"},"content":{"rendered":"<h3>Prerequisite:<\/h3>\n<p>It is recommended to have basic understanding of CHEF and its components. In case you want to go through the basics of CHEF click <a href=\"http:\/\/www.tothenew.com\/blog\/understanding-chef-and-writing-cookbooks\/\">here<\/a><\/p>\n<h3>Use Case:<\/h3>\n<p>If you are already using CHEF in your environment, you often write new cookbooks and for testing those you either need to start new virtual machines or cloud instances. This activity usually takes few minutes but there is additional cost associated with launching new cloud instances. CHEF test kitchen has enabled us to reduce new cookbook\/recipes testing time to minutes by provisioning VAGRANT box on our local workstation.<\/p>\n<p>In this blog, I will be using mongodb-docker cookbook for demonstrating CHEF test kitchen<\/p>\n<h3>Install Test Kitchen, VAGRANT and VirtualBox:<\/h3>\n<ol>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Chef Test Kitchen: 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.<\/span><\/li>\n<\/ol>\n<\/ol>\n<p>[js]$ gem install test-kitchen[\/js]<\/p>\n<ol>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Virtualbox: VirtualBox is powerful Cross-platform Virtualization Software for x86-based systems. &#8220;Cross-platform&#8221; means that it can be installed on Windows, Linux, Mac OS X and Solaris x86 computers.<\/span><\/li>\n<\/ol>\n<\/ol>\n<p>[js]$ sudo apt-get install virtualbox[\/js]<\/p>\n<ol>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">VAGRANT: VAGRANT not only creates virtual machines, it mainly automates the work of setting up development environment.<\/span><\/li>\n<\/ol>\n<\/ol>\n<p>[js]$ sudo apt-get install vagrant[\/js]<\/p>\n<h3>Steps to test MongoDB Replica Set Cookbook <a href=\"https:\/\/github.com\/neerjaj2\/chef\/blob\/master\/cookbooks\/docker-mongodb\/recipes\/default.rb\" target=\"_blank\">recipe<\/a> with CHEF Test Kitchen:<\/h3>\n<p>Kitchen.yml can be created in chef-repo directory or in the recipe directory. If you initialize kitchen in recipe directory, recipe name will be automatically added to the kitchen.yml.<\/p>\n<ol>\n<ol>\n<li>You can create kitchen.yml file in the chef-repo directory (as shown below) or in specific cookbook directory.<\/li>\n<\/ol>\n<\/ol>\n<p>[js]$ kitchen init[\/js]<\/p>\n<ol>\n<ol>\n<li>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.<\/li>\n<\/ol>\n<\/ol>\n<p>[js]<br \/>\n&#8212;<br \/>\ndriver:<br \/>\nname: vagrant<\/p>\n<p>provisioner:<br \/>\nname: chef_zero<\/p>\n<p>platforms:<br \/>\n&#8211; name: ubuntu-14.04<br \/>\ndriver:<br \/>\ncustomize:<br \/>\nmemory: 256<\/p>\n<p>suites:<br \/>\n&#8211; name: default<br \/>\nrun_list:<br \/>\n&#8211; recipe[mongodb-docker::default]<br \/>\nattributes:[\/js]<\/p>\n<ol>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To create VAGRANT machine use below-mentioned command:<\/span><\/li>\n<\/ol>\n<\/ol>\n<p>[js]$ kitchen list [\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-30942\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/12\/CTK_Kitchen_list_0.png\" alt=\"CTK_Kitchen_list_0\" width=\"1299\" height=\"59\" \/><\/p>\n<p>[js]$ kitchen create [\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-30944\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/12\/CTK_kitchen_create_1.png\" alt=\"CTK_kitchen_create_1\" width=\"1300\" height=\"741\" \/><\/p>\n<ol>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To execute recipe on the VAGRANT virtual machine, use the below-mentioned command:<\/span><\/li>\n<\/ol>\n<\/ol>\n<p>[js]$ kitchen converge [\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-30943\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/12\/CTK_kitchen_converge_2.png\" alt=\"CTK_kitchen_converge_2\" width=\"1299\" height=\"393\" \/><\/p>\n<ol>\n<ol>\n<li>To login to the VAGRANT vm, use kitchen login command as shown below:<\/li>\n<\/ol>\n<\/ol>\n<p>[js]$ kitchen login[\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-30947\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/12\/CTK_Kitchen_login_4.png\" alt=\"CTK_Kitchen_login_4\" width=\"1277\" height=\"249\" \/><\/p>\n<ol>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">And after testing if you want to delete the setup i.e. vagrant vm, use the command mentioned-below:<\/span><\/li>\n<\/ol>\n<\/ol>\n<p>[js]$ kitchen destroy[\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-30945\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/12\/CTK_Kitchen_Destroy_4.png\" alt=\"CTK_Kitchen_Destroy_4\" width=\"1299\" height=\"144\" \/><\/p>\n<p>Get in touch with our <a title=\"Chef DevOps\" href=\"http:\/\/www.tothenew.com\/devops-chef-puppet-docker\" target=\"_blank\">Chef devOps<\/a> in case of any query.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisite: It is recommended to have basic understanding of CHEF and its components. In case you want to go through the basics of CHEF click here Use Case: If you are already using CHEF in your environment, you often write new cookbooks and for testing those you either need to start new virtual machines or [&hellip;]<\/p>\n","protected":false},"author":216,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":17},"categories":[1174],"tags":[2945,2946,2944],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/30941"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/216"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=30941"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/30941\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=30941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=30941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=30941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}