Creating a Chef Cookbook for Windows

February 16, 2017

The Berkshelf documentation moved to the “official” Chef docs. I found it a little confusing but complete. The purpose of this post is to remind future self how to do this, without having to dig through the docs again. These instruction assume the following is installed

  • ChefDK Version 1.1.16
  • Vagrant
  • Vagrant winrm plugin
  • VirtualBox

I create a custom Windows 10 Vagrant box using Packer. Then added it to my computer using the following

vagrant add path/to/windows10min-virtualbox.box –name win10

I wanted to configure Test Kitchen to

  • Create a Windows 10 VM
  • Write smoke tests using Inspec
  • Run unit tests using ChefSpec
  • Use Berkshelf

Creating a Blank Chef Cookbook

Run the following command. -b will add a berksfile

chef generate cookbook COOKBOOK_NAME -b

Update the kitchen.yml file to look like the following

— driver: name: vagrant customize: memory: 2048 cpus: 2

provisioner:
name: chef_zero
always_update_cookbooks: true

verifier:
name: inspec

transport:
name: winrm

platforms:

  • name: win10
    os_type: windows
    shell_type: powershell

suites:

  • name: default
    run_list:
  • recipe[COOKBOOK_NAME::default]
    verifier:
    inspec_tests:
  • test/smoke/default
    attributes:

Testing your blank Chef cookbook and kitchen configuration

This should create the VM

kitchen create

This should run the default recipe

kitchen converge

This should run tests

kitchen verify

Run specs

chef exec rspec

Build awesome things for fun.

Check out our current openings for your chance to make awesome things with creative, curious people.

Explore SEP Careers »

You Might Also Like