Match WSL installed Vagrant with Windows installed Vagrant

This commit is contained in:
Chris Roberts 2017-05-08 10:06:27 -07:00
parent 83b0c87f52
commit 4df4f77bf6
3 changed files with 33 additions and 0 deletions

View File

@ -891,5 +891,9 @@ module Vagrant
class VMPowerOffToPackage < VagrantError
error_key(:power_off, "vagrant.actions.vm.export")
end
class WSLVagrantVersionMismatch < VagrantError
error_key(:wsl_vagrant_version_mismatch)
end
end
end

View File

@ -293,6 +293,7 @@ module Vagrant
# @param [Logger] logger Optional logger to display information
def wsl_init(logger=nil)
if wsl? && ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"]
wsl_validate_matching_vagrant_versions!
shared_user = ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"]
if logger
logger.warn("Windows Subsystem for Linux detected. Allowing access to user: #{shared_user}")
@ -310,6 +311,24 @@ module Vagrant
end
end
# Confirm Vagrant versions installed within the WSL and the Windows system
# are the same. Raise error if they do not match.
def wsl_validate_matching_vagrant_versions!
valid = false
result = Util::Subprocess.execute("vagrant.exe", "version")
if result.exit_code == 0
windows_version = result.stdout.match(/Installed Version: (?<version>.+$)/)
if windows_version
valid = windows_version[:version] == Vagrant::VERSION
end
end
if !valid
raise Vagrant::Errors::WSLVagrantVersionMismatch,
wsl_version: Vagrant::VERSION,
windows_version: windows_version ? windows_version[:version] : "unknown"
end
end
# @private
# Reset the cached values for platform. This is not considered a public
# API and should only be used for testing.

View File

@ -1520,6 +1520,16 @@ en:
VM must be running to open SSH connection. Run `vagrant up`
to start the virtual machine.
test_key: "test value"
wsl_vagrant_version_mismatch: |-
Vagrant cannot currently enable access to manage machines within the Windows
environment because the version of Vagrant installed on Windows does not
match this version of Vagrant running within the Windows Subsystem for Linux.
Please ensure both installation of Vagrant are the same. If you do not want
update your Vagrant installations you can disable Windows access by unsetting
the `VAGRANT_WSL_ACCESS_WINDOWS_USER` environment variable.
Windows Vagrant version: %{windows_version}
Windows Subsystem for Linux Vagrant version: %{wsl_version}
#-------------------------------------------------------------------------------
# Translations for config validation errors