devopsgroup-io / vagrant-hostmanager

:pencil: A Vagrant plugin that manages hosts files within a multi-machine environment.
Mozilla Public License 2.0
1.46k stars 146 forks source link

Windows guests break with Vagrant 1.7.4 #157

Closed apancutt closed 8 years ago

apancutt commented 9 years ago

Running Vagrant 1.7.4 and vagrant-hostmanager 1.6.0

Multi-machine setup (one named "linux", the other "windows). When trying to run vagrant up I get the following error:

==> linux: Updating /etc/hosts file on active guest machines...
The box is not able to report an address for WinRM to connect to yet.
WinRM cannot access this Vagrant environment. Please wait for the
Vagrant environment to be running and try again.

This suggests the plugin is trying to update the hosts file on the windows machine which has not booted yet - it boots after the linux machine.

A subsequent run of vagrant up (or vagrant hostmanager) successfully updates the linux hosts file, but fails to update windows with another error:

==> windows: Updating /etc/hosts file on active guest machines...
The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mv -force /tmp/hosts C:\Windows\System32\drivers\etc\hosts
if ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }

Stdout from the command:

Stderr from the command:

#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">mv : Cannot create a file when that file already exists._x000D__x000A_</S><S S="Error">At line:1 char:1_x000D__x000A_</S><S S="Error">+ mv -force /tmp/hosts C:\Windows\System32\drivers\etc\hosts_x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : WriteError: (C:\tmp\hosts:DirectoryInfo) [Move-I _x000D__x000A_</S><S S="Error">   tem], IOException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Co _x000D__x000A_</S><S S="Error">   mmands.MoveItemCommand_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>

Note that both problems disappear if I roll back to Vagrant 1.6.5.

apancutt commented 9 years ago

The first issue no longer applies when using VirtualBox 5.0.0

The second issue still exists - the hosts file on Windows does not update and forces an error.

The /tmp/hosts path resolves to C:\tmp\hosts which is a directory, containing one file hosts.windows.

Manually running the command in Powershell reproduces the error:

PS C:\Users\vagrant> mv -force /tmp/hosts C:\Windows\System32\drivers\etc\hosts
mv : Cannot create a file when that file already exists.
At line:1 char:1
+ mv -force /tmp/hosts C:\Windows\System32\drivers\etc\hosts
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : WriteError: (C:\tmp\hosts:DirectoryInfo) [Move-Item], IOException
+ FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

However, changing the source path to /tmp/hosts/host.windows works:

PS C:\Users\vagrant> mv -force /tmp/hosts/hosts.windows C:\Windows\System32\drivers\etc\hosts
PS C:\Users\vagrant> echo $?
True
seth-reeser commented 8 years ago

Can you please try and reproduce? This should be resolved.

apancutt commented 8 years ago

Apologies, I should have reported that the issue has since been resolved. I'll admit it's been a while so not sure whether it was a Vagrant or hostmanager upgrade that fixed the issue. Either way, thanks!