ContributorsUp to 5 hoursHere you'll make sure that your workstation is set up for Chef development and also install the virtualization software.
The setup process involves downloading the evaluation version of Windows Server 2012 R2 as an ISO image and running a Packer template to convert the ISO image to a format that Vagrant and VirtualBox can use. The Packer template can take several hours to finish. However, you don't need to be present while it runs.
This module uses Test Kitchen along with VirtualBox and Vagrant to manage test instances. This combination is popular with Chef users because it uses free software and is easy to set up.

VirtualBox is a hypervisor that manages your virtual machine instances. Think of it as the software that hosts your VM instances.
Vagrant makes it easier to work with hypervisors such as VirtualBox. Vagrant uses a configuration file, called a Vagrantfile, to describe aspects of the virtual machine such as available memory, host name, and network settings.
Vagrant also provides access to base virtual machine images, called boxes. Vagrant Cloud is a place where you can access prebuilt boxes or upload new boxes for others to use. Bento is a Chef project that provides ready-to-use Vagrant boxes for many common platforms. However, due to the way Windows Server is licensed, you'll need to build your own base box.
Test Kitchen enables you to specify details about your virtual machine, including its operating system, available memory, host name, and network settings, and how to run Chef – including which recipes and which tests to run. Test Kitchen builds the Vagrantfile for you and is the interface you use to create, destroy, and run Chef on your instances. Test Kitchen also downloads the Vagrant box for you as needed (when the box is available from a remote source, such as Atlas).
| This page explains the manual steps to help you understand exactly what software you need to install and how to install it. Alternatively, you can also run the ChefDK_Bootstrap script to set up your Windows or Mac workstation for Chef development. The script installs commonly used development tools such as the Atom text editor, Git, VirtualBox, and Vagrant. |
Before you begin
Your workstation – the system from which you develop your cookbooks – can be a physical machine or a virtual machine that supports nested virtualization.
Ensure that your workstation supports and is configured to use CPU virtualization. This setting is typically configured through your system's BIOS. If you're using a virtual machine as your workstation through a program such as VMware Fusion, ensure that nested virtualization is enabled on the workstation VM.
Also ensure that your workstation meets the system requirements for running VirtualBox. We recommend your system have at least 50 GB of free disk space available and at least 8 GB of memory.
VirtualBox does not run in virtualized workstation environments such as Amazon EC2 or a VirtualBox host instance. You can try a different option if you're unable to run VirtualBox.
1. Set up your workstation for Chef development
Although this module doesn't involve the Chef server or bootstrapping a node, we recommend that you complete Manage a Windows Server node with Chef server before starting this module.
If you prefer to learn about local development now, before learning how to bootstrap a node, perform these steps to set up your workstation. Then come back to this page.
At this point, your workstation should:
- have the latest version of Chef Workstation.
- have a programmer's text editor that you're comfortable working with.
- have the
~/learn-chef directory for you to work in. - have Git and an RDP client.
Having Git is important because you'll use it to download starter code to work with.
Having an RDP client is important because you can use it to log in to your Windows Server instance to verify your work.
If your workstation is running Windows, remember to open the Chef Workstation desktop shortcut. The desktop shortcut brings up a PowerShell session that's configured to work with Chef.

2. Install VirtualBox and Vagrant
If you already use VirtualBox and Vagrant or have gone through the Learn Chef modules that use them, then you're already set up.
If you're new to VirtualBox and Vagrant, the Learn the Chef basics module can help you get set up. You can follow the steps that have you bring up a CentOS instance to verify the installation. However, you don't need to connect to or install Chef Workstation on your CentOS instance.
3. Build a Windows Server 2012 R2 Vagrant box
When Vagrant creates a virtual machine instance, it loads an image, or box, which captures a snapshot of the operating system in a preconfigured state.
For some operating systems, Test Kitchen can automatically download a Vagrant box for you. It's also common to build your own box if you need it to contain certain software or security updates. Because of the way Windows Server 2012 R2 is licensed, we can't provide you with a preconfigured box. Packer is a popular way to automate the creation of Vagrant boxes.
Here, you'll perform these steps to use the evaluation version (an ISO image) of Windows Server 2012 R2 to build your own box.
- Install Packer on your workstation.
- Get the packer-templates project from GitHub.
- Run the Packer template to generate a Vagrant box.
- Register the box with your local Vagrant catalog.
Read this blog post for more information about the process.
3.1 Install Packer on your workstation
First, install Packer.
Packer is distributed through a .zip file. After you extract the .zip file, add the path to packer to your PATH environment variable or use the full path to in the steps that follow.
3.2 Get the packer-templates project from GitHub
Now download the latest packer-templates project from GitHub. This template downloads the evaluation version of Windows Server 2012 R2 as an ISO image, installs all Windows updates, and reduces the size of the image as much as possible.
If you use Git, clone the repository to where you do your development work. Alternatively, you can clone the repository to the ~/learn-chef directory.
Terminal: ~/learn-chef
$ | git clone https://github.com/mwrock/packer-templates.gitCloning into 'packer-templates'...remote: Counting objects: 186, done.remote: Total 186 (delta 0), reused 0 (delta 0), pack-reused 186Receiving objects: 100% (186/186), 33.37 KiB | 0 bytes/s, done.Resolving deltas: 100% (87/87), done.Checking connectivity... done.
|
If you don't use Git, you can download a .zip file that contains the latest version from GitHub.

3.3 Run the Packer template to generate a Vagrant box
Now run Packer to apply the template. This process can take several hours because it downloads the ISO image and applies the latest Windows updates.
Terminal: ~/learn-chef/packer-templates
$ | packer build -force -only virtualbox-iso vbox-2012r2.jsonvirtualbox-iso output will be in this color. ==> virtualbox-iso: Downloading or copying ISO virtualbox-iso: Downloading or copying: http://care.dlservice.microsoft.com/dl/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.17050.WINBLUE_REFRESH.140317-1640_X64FRE_SERVER_EVAL_EN-US-IR3_SSS_X64FREE_EN-US_DV9.ISO virtualbox-iso: Download progress: 0% virtualbox-iso: Download progress: 1% virtualbox-iso: Download progress: 2%[...] virtualbox-iso: Download progress: 100%==> virtualbox-iso: Deleting previous output directory...==> virtualbox-iso: Creating floppy disk... virtualbox-iso: Copying: answer_files/2012_r2/Autounattend.xml virtualbox-iso: Copying: scripts/postunattend.xml virtualbox-iso: Copying: scripts/boxstarter.ps1 virtualbox-iso: Copying: scripts/package.ps1==> virtualbox-iso: Creating virtual machine...==> virtualbox-iso: Creating hard drive...==> virtualbox-iso: Attaching floppy disk...==> virtualbox-iso: Creating forwarded port mapping for SSH (host port 3165)==> virtualbox-iso: Executing custom VBoxManage commands... virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1443702410 --natpf1 guest_winrm,tcp,,55985,,5985 virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1443702410 --memory 2048 virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1443702410 --vram 36 virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1443702410 --cpus 2==> virtualbox-iso: Starting the virtual machine...==> virtualbox-iso: Waiting 10s for boot...==> virtualbox-iso: Typing the boot command...==> virtualbox-iso: Waiting for WinRM to become available...==> virtualbox-iso: Connected to WinRM!==> virtualbox-iso: Uploading VirtualBox version info (5.0.4)==> virtualbox-iso: Gracefully halting virtual machine... virtualbox-iso: Removing floppy drive...==> virtualbox-iso: Preparing to export machine... virtualbox-iso: Deleting forwarded port mapping for SSH (host port 3165)==> virtualbox-iso: Exporting virtual machine... virtualbox-iso: Executing: export packer-virtualbox-iso-1443702410 --output output-virtualbox-iso/packer-virtualbox-iso-1443702410.ovf==> virtualbox-iso: Unregistering and deleting virtual machine...==> virtualbox-iso: Running post-processor: vagrant==> virtualbox-iso (vagrant): Creating Vagrant box for 'virtualbox' provider virtualbox-iso (vagrant): Copying from artifact: output-virtualbox-iso/packer-virtualbox-iso-1443702410-disk1.vmdk virtualbox-iso (vagrant): Copying from artifact: output-virtualbox-iso/packer-virtualbox-iso-1443702410.ovf virtualbox-iso (vagrant): Renaming the OVF to box.ovf... virtualbox-iso (vagrant): Using custom Vagrantfile: vagrantfile-windows.template virtualbox-iso (vagrant): Compressing: Vagrantfile virtualbox-iso (vagrant): Compressing: box.ovf virtualbox-iso (vagrant): Compressing: metadata.json virtualbox-iso (vagrant): Compressing: packer-virtualbox-iso-1443702410-disk1.vmdkBuild 'virtualbox-iso' finished. ==> Builds finished. The artifacts of successful builds are:--> virtualbox-iso: VM files in directory: output-virtualbox-iso--> virtualbox-iso: 'virtualbox' provider box: windows2012r2min-virtualbox.box
|
3.4 Register the box with your local Vagrant catalog
After the Packer process finishes, confirm that windows2012r2min-virtualbox.box exists in your packer-templates directory.
Terminal: ~/learn-chef/packer-templates
$ | ls windows2012r2min-virtualbox.boxwindows2012r2min-virtualbox.box
|
Now run this command to add the box to your local Vagrant catalog.
Terminal: ~/learn-chef/packer-templates
$ | vagrant box add windows-2012r2 windows2012r2min-virtualbox.box==> box: Adding box 'windows-2012r2' (v0) for provider: box: Downloading: file:///Users/user/Development/mwrock/packer-templates/windows2012r2min-virtualbox.box==> box: Successfully added box 'windows-2012r2' (v0) for 'virtualbox'!
|
Now confirm that the box is successfully registered.
Terminal: ~/learn-chef/packer-templates
$ | vagrant box listwindows-2012r2 (virtualbox, 0)
|
4. Install the vagrant-winrm plugin
Test Kitchen uses the vagrant-winrm Vagrant plugin to enable the host machine to connect to Windows instances over the WinRM protocol.
Install the plugin like this.
Terminal: ~
$ | vagrant plugin install vagrant-winrmInstalling the 'vagrant-winrm' plugin. This can take a few minutes...The `minitar` executable is no longer bundled with `minitar`. If you areexpecting this executable, make sure you also install `minitar-cli`.Installed the plugin 'vagrant-winrm (0.7.0)'!
|