2/16/2015 - 7:17 PM

Setup vagrant boxes

Setup vagrant boxes

Setup vagrant boxes

Since released vagrant boxes, it' no longer necessary to manually import the ova file to virtualbox, as mentioned here.

However, the guys at didn't configured the box to work with WinRM. This how-to addresses that, presenting steps to proper repackage these boxes, adding WinRM support. Additionally configures chocolatey package manager and puppet provisioner.


The host machine must have Vagrant and VirtualBox installed.

1. Configure the Vagrantfile

The same Vagrantfile can be used with different versions of available boxes. Read the comments in the file for details.

# -*- mode: ruby -*-
# vi: set ft=ruby :

# box name into env var, same script can be used with different boxes. Defaults to win7-ie11.
box_name = box_name = ENV['box_name'] != nil ? ENV['box_name'].strip : 'win7-ie11'
# box repo into env var, so private repos/cache can be used. Defaults to
box_repo = ENV['box_repo'] != nil ? ENV['box_repo'].strip : ''

Vagrant.configure("2") do |config|
  # If the box is win7-ie11, the convention for the box name is = "" + box_name
  # If the box is win7-ie11, the convention for the box url is
  config.vm.box_url = box_repo + "/vagrant-" + box_name
  # big timeout since windows boot is very slow
  config.vm.boot_timeout = 500

  # rdp forward "forwarded_port", guest: 3389, host: 3389, id: "rdp", auto_correct: true

  # winrm config, uses default user/password. If other credentials are used must be changed here
  config.vm.communicator = "winrm"
  config.winrm.username = "IEUser"
  config.winrm.password = "Passw0rd!"

  config.vm.provider "virtualbox" do |vb|
    # first setup requires gui to be enabled so scripts can be executed in virtualbox guest screen
    #vb.gui = true
    vb.customize ["modifyvm", :id, "--memory", "1024"]
    vb.customize ["modifyvm", :id, "--vram", "128"]
    vb.customize ["modifyvm", :id,  "--cpus", "2"]
    vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]

2. Setup

Create a directory and a Vagrantfile file with the contents from previous section. For the first run, uncomment the vb.gui=true line to disable VirtualBox headless mode. Start the box running the command:

# uncomment below to change the box version and repo
# export box_name=win7-ie11 && export box_repo=
$ vagrant up

When the machine is booted, do the following steps on VirtualBox guest window:

@echo off
set WINRM_EXEC=call %SYSTEMROOT%\System32\winrm
%WINRM_EXEC% quickconfig -q
%WINRM_EXEC% set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
%WINRM_EXEC% set winrm/config @{MaxTimeoutms="1800000"}
%WINRM_EXEC% set winrm/config/client/auth @{Basic="true"}
%WINRM_EXEC% set winrm/config/service @{AllowUnencrypted="true"}
%WINRM_EXEC% set winrm/config/service/auth @{Basic="true"}
  • At this time the up command will be probably verifying if the guest booted properly. Since you just configured WinRM, the command should terminate successfully.

3. Chocolatey and Puppet

Run the following script to configure chocolatey and puppet on the guest machine:

@echo off
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString(''))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
choco install -y puppet

4. Package

Since there's a lot of Windows specific configuration, you can include the Vagrantfile in the package command so winrm and virtualbox configuration get's default values when the repackaged is used for other purposes. Remember to run the command in the same directory the Vagrantfile resides:

$ vagrant package --output "yourboxname" --Vagrantfile Vagrantfile

After that you're all set!