If you are trying to reproduce this exactly, I'm using the following environment:
- VirtualBox 4.3.12
- Bills Kitchen 3.0-rc4 (includes Vagrant, Packer, Chef, etc)
First challenge is to get a windows basebox from somewhere. I couldn't find a good one, so built one myself from the windows/boxcutter packer templates:
git clone https://github.com/boxcutter/windows.git windows-boxes
cd windows-boxes
make virtualbox/eval-win7x86-enterprise
This takes a while (~45 minutes, depending on your internet connection).
Once the basebox is built, you can import it to Vagrant:
vagrant box add boxcutter/eval-win7x86-enterprise box/virtualbox/eval-win7x86-enterprise-nocm-1.0.4.box
Next I was trying to figure out a minimal Vagrantfile example, which works for all the basic Vagrant things, e.g.:
vagrant up
should not work reliably (not hang / run into timeouts)vagrant ssh
should workvagrant ssh -c "echo foo"
should run the commandvagrant provision
should work, with eitherinline:
orpath:
(.bat / .ps) "shell" provisioner- synced folders should work (via vboxsf or smb ideally)
The Vagrantfile that is packaged within the above built basebox already includes some windows specific settings, such as setting config.vm.communicator = "winrm"
and config.vm.guest = :windows
, so we don't need to repeat that in our Vagrantfile.
So this was my first try:
Vagrant.configure(2) do |config|
config.vm.box = "boxcutter/eval-win7x86-enterprise-nocm"
config.vm.provision "shell", inline: "echo hello!"
config.vm.synced_folder ".", "/vagrant", disabled: true
end
No luck though...
vagrant up
works, but hangs and never completes (I can Ctrl+C though and continue working with the VM)vagrant ssh
works, yay! :-)vagrant ssh -c "echo foo"
drops me into the shell instead of executing the commandvagrant provision
hangs and times out- synced folders I explicitly disabled for now to make it even simpler
Since Packer only supports SSH I assume the boxcutter template has both WinRM and SSH configured. The fact that
vagrant ssh
works is a good indication of that.Don't use the vagrant-windows plugin like @chrisbaldauf mentioned, it was meant for Vagrant < 1.5 that didn't natively support Windows guests. Newer versions of Vagrant have native WinRM support.
Vagrant has some issues with swallowing connection errors (fixed in master), so you're left with a hung box instead of failing fast with an authentication error telling you what the underlying problem is. Try running vagrant with the
--debug
flag, this will help isolate the actual error. More than likely you don't have WinRM properly configured or are using the wrong username and password. This is the PowerShell script I use to configure WinRM via my Packer build.