This is the second in a series of articles being written about using automation on a windows workstation. This series of articles will focus on doing automation on Windows because it seems to be the platform with the most need for coverage. The first article introduced vagrant for virtualization.
Goal: Repeatable Generation of Windows Vagrant Box(s)
Entirely command line driven step by step instructions in this article will be used for creating running Windows VM(s) in Virtual Box via Vagrant on a Windows host so that we can build further automation in a safe isolated environment for usage on other windows machines, even the machine that is hosting the VM(s). The VM(s) provide a safe sandbox to try things without making a mess of the host operating system environment. Additionally, it lets you use server OS(s) on your workstation to do your development.
Installing the prerequisite tools
Chocolatey is the first tool needed. It is a package management solution for windows and will allow the installation of further tooling. The following are the scripts that can be run to install it.
Firewall Note: If you whitelist outbound connections then you'll need to add an outbound rule for powershell. For me that was "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe". Additionally, after installing Chocolatey, you'll need to whitelist it for outbound connections. For me the executable was located at "C:\ProgramData\chocolatey\choco.exe"
Option 1. Command line Option.
Options 2. Powershell Option. Make sure Execution Policy in Powershell is at least Bypass
The above instructions came straight from https://chocolatey.org/
Install Chocolatey Packages: Cyg-Get, Cygwin, vagrant, packer, virtualbox
When you install cyg-get you will be asked to install Cygwin first.
Firewall Note: Before isntalling "cyg-get" via choco you will need to pre-whitelist the cygwin setup executable at ""C:\tools\cygwin\cygwinsetup.exe", then it will be able to access the download locations when being run.
The latest packer in the chocolatey repository at the time of writing this article was (0.8.1) and it did not support the latest version of Virtual Box (5.0) therefore the specific version that is suppored (4.3.28) needs to be installed.
After installing vagrant, in order to make it usable in cygwin I needed to add the path to vagrant to the PATH in cygwin, this was easily doable by adding the path to my “.bash_profile”. Please note that the following is run in a Cygwin prompt.
Install Cygwin Packages: git, make, openssh
Installing these are required for getting the source code and making/using the vagrant boxes.
Clone code to make the Windows Box via Packer
Setup ssh key
Startup a Cygwin terminal and add code to automatically start ssh-agent when opening cygwin terminal. Then, add your key to access Github to ~/.ssh directory and set to mode 600.
Firewall Note: ssh needs outbound connectivity to the internet for git cloning to operate properly, this was located at "c:\tools\cygwin\bin\ssh.exe"
Clone boxcutter/windows from Github
Boxcutter is a github user with many repositories for different OS templates. Cloning the repo will give you the code to create:
- win2012r2-datacenter-nocm, VMware 4.3GB/VirtualBox 4.2GB
- win2012-datacenter-nocm, VMware 3.7GB/VirtualBox 3.5GB
- win2008r2-datacenter-nocm, VMware 3.0GB/VirtualBox 2.8GB
- win81x64-enterprise-nocm, VMware 4.0GB/VirtualBox 3.6GB
- win8x64-enterprise-nocm, VMware 3.6GB/VirtualBox 3.3GB
- win7x64-enterprise-nocm, VMware 3.5GB/VirtualBox 3.2GB
Create Windows Box(s)
Navigate into the cloned repository and create Virtual Boxes as follows:
Firewall Note: Allow packer provisioner for virtualbox outbound to the internet, this was located at "C:\ProgramData\chocolatey\lib\packer\tools\packer-builder-virtualbox-iso.exe"
Please be patient it does take a fairly long time to complete the creation of the VMs. You will see the progress on the screen. If you create both you will 2 boxs waiting for you. See Screenshots at beginning of article, they correspond to the two VMs I have created:
- 4.1G Jul 30 20:15 eval-win2012r2-standard-ssh-nocm-1.0.4.box
- 5.9G Jul 30 02:11 eval-win81x64-enterprise-ssh-nocm-1.0.4.box
In the next article I will show of a way to use these boxes in a repeatable process for creating VM(s). However, if you know how to use vagrant effectively already, then by all means jump ahead and use these Vagrant box(s).