Vagrant and Hyper-V Issues

written in chef, vagrant

Some annoyances in Vagrant 1.7.4

We have been using Vagrant, Chef and Hyper-V for a work project for a few months now, and recently have been running into a few annoying bugs.


The first issue caught us out after we upgraded to 1.7.4 from 1.7.2. The error we were getting looked something like this:

The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

cmdkey /add:xxx.xxx.xxx.xxx /user:DOMAIN\user /pass:Password

Stdout from the command:

Stderr from the command:

Exception calling "RegisterTaskDefinition" with "7" argument(s): "The username or password is incorrect. (Exception from HRESULT: 0x8007052E)"
At C:\tmp\vagrant-elevated-shell.ps1:58 char:1
+ $folder.RegisterTaskDefinition($task_name, $task, 6, $username, $password,1, $n ...

I could not work this one out and reverted to 1.7.2, after a few months I thought I had gotten a lead on the issue when I noticed that there were a few winRM commands executed on our base box. After reverting them and trying a few different combinations I was still getting the same error.

My next thought was maybe the username needs to be fully qualified with the domain name, I tried adding this into the config in the vagrant file but this caused other errors much earlier in the vagrant up process.

So I jumped onto the VM and edited the PowerShell script mentioned in the error output (C:\tmp\vagrant-elevated-shell.ps1) and prepended the username variable with the domain name, this was swiftly removed after doing a vagrant up as this file is copied to the guest from the host. I edited the host copy and got the same error. As a last resort I added some logging to the script and ran a vagrant up again. This time I noticed that the password was incorrect!

Our password contains dollar ($) symbols and these were being stripped out in the script! I’ve been caught by this issue before, PowerShell needs the dollar sign to be escaped by a back-tick (`).

I sauntered over to a colleagues desk to brag at this major victory for mankind and he was like oh yea I’ve seen a commit message with a fix for that!

We noticed though that our local version was different than the one in the commit message, the change had been lost by this newer commit

I forked the vagrant repo, made the fix and submitted a pull request, which you can view here someone else had a similar issue and raised a defect have a look at my comment for the steps on patching your environment.

Hopefully my PR will be available in the next release of Vagrant.


Another issue that we were having was our vagrant provision was taking more than 2 hours to complete and was timing out for no reason. I stumbled upon this issue on GitHub which references the same PowerShell modified in our first issue. The file (elevated_shell.ps1.erb) has the following line:

<ExecutionTimeLimit>PT2H</ExecutionTimeLimit>

Changing this to:

<ExecutionTimeLimit>PT4H</ExecutionTimeLimit>

Fixed our issue, I’m hoping this is also a temporary patch as there is already a PR which makes this value configurable.


Comments