Set up Cookbook for Windows 10 and macOS Platforms
Estimated time: 1 hour (with your own virtual machines)
This step introduces you to fundamentals of cookbook development and walks you through the process of creating, editing, and testing a simple cookbook. These are the same basic steps that you will expand on in developing your Chef Desktop cookbook.
- Learn about testing with Test Kitchen
- Set up your Chef development environment
- Make a demo cookbook
- Test your cookbook locally
- Test your cookbook with Test Kitchen, once you have your virtual machine images
Testing is central to good software development. Testing your Chef Desktop cookbook provides you the opportunity to detect and correct problems before putting changes into production. Testing saves time and money, but it adds value by helping your organization achieve and maintain operational velocity.
It is important to understand your operating license and service agreements. The best place to begin is find and understand your SLA:
Setup Your Development Environment
In this step, you will prepare your workstation for developing, testing, and deploying the Chef Desktop cookbook.
Create your local repo
You will need a local repository on your workstation for storing your cookbooks and related chef work, and for sharing it with GitHub or another version control system.
From the command line in your root folder (c:\ or ~/), run:
chef generate repo my_repo
Make Your First Cookbook
This is a practice cookbook to understand how to test.
Create your cookbook
chef generate cookbook my_repo/cookbooks/my_cookbook
Open your repo in Visual Studio Code. The one key file you will want to manage is the
metadata.rbfile. Please take a moment now to add your contact information and enter a starting version number for your cookbook.
name 'my_cookbook' maintainer 'The Authors' maintainer_email 'email@example.com' license 'All Rights Reserved' description 'Installs/Configures my_cookbook' version '0.1.0' chef_version '>= 16.0'
Edit the default recipe
my_repo\cookbook\my_cookbook\recipes\default.rbin Visual Studio and add:
powershell_script 'get my path' do code <<-CODE [Environment]::GetEnvironmentVariable("Path") CODE end
bash 'get my path' do user 'root' code <<-EOH echo $PATH EOH end
- Spacing matters! Be mindful of spaces
- Use LF line spacing and not CRLF. (Look to the bottom right of the status bar in Visual Studio Code)
If you want to use the Chef Desktop cookbook you received from Chef instead of creating a new one, then navigate and unzip that file into your cookbooks directory. Now you have two cookbooks. Update the
metadata.rb file for the Chef Desktop cookbook to add your contact details.
Chef Desktop comes with a large number of options for configuring your Windows and Mac desktops. Look through the
windows.rb files to explore what settings you want to turn on for your testing and evaluation. For those resources you do not want to explore yet, set their action to ‘:nothing’. See the Chef Desktop cookbook documentation for more information about settings.
Testing cookbooks with Test Kitchen
Test Kitchen was installed with Chef Workstation. It provides Chef Infra with a testing harness for cookbooks that uses virtual machines(VMs). Consult your Apple and Microsoft licenses and service level agreements (SLA) to understand your options for acquiring or creating VMs for development.
Test Kitchen Integrations
Test Kitchen uses a driver plugin architecture to enable Test Kitchen to test instances on cloud providers such as Amazon EC2, Google Compute Engine, and Microsoft Azure. You can also test on multiple local hypervisors, such as VMware, Hyper-V, or VirtualBox. Test Kitchen Documentation and the Test Kitchen GitHub Repository.
Run Test Kitchen
Run the Virtual Devices
When working with desktop cookbook that you received from Chef, you downloaded the two virtual devices, also called testing images. Now issue the following command to get them started:
Apply the Cookbooks to the Images
Run the following command to apply, or ‘converge’, the cookbooks with the base OS image:
Verify the settings
Confirm that the converged code is the code that you meant to apply. In VSCode, navigate to the
test\integration\defaultdirectory and examine the generated integration tests. Carefully go through these tests and adjust them to match the setting to the changes in the
default.rbfile. Next, run:
If any of the tests fail, check the output and compare your settings in the
windows.rbfiles against the matching tests.
When you finish with your testing, you can run the following command to delete the running test images:
Once you are familiar with Test Kitchen, you can perform all of the steps at once, including cleanup, with:
Was this page helpful?