From 62edaf56230eaf87fb340173c05f3096d8d36e80 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 4 May 2017 18:47:59 -0700 Subject: [PATCH 1/2] Allow shell to be defined when calling #execute --- plugins/communicators/winssh/communicator.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/communicators/winssh/communicator.rb b/plugins/communicators/winssh/communicator.rb index e0ca8226b..37fe347da 100644 --- a/plugins/communicators/winssh/communicator.rb +++ b/plugins/communicators/winssh/communicator.rb @@ -19,6 +19,7 @@ module VagrantPlugins }.merge(opts) sudo = opts[:sudo] + shell = (opts[:shell] || machine_config_ssh.shell).to_s @logger.info("Execute: #{command} (sudo=#{sudo.inspect})") exit_status = nil @@ -31,10 +32,10 @@ module VagrantPlugins stderr_data_buffer = '' tfile = Tempfile.new('vagrant-ssh') - remote_ext = machine_config_ssh.shell.to_s == "powershell" ? "ps1" : "bat" + remote_ext = shell == "powershell" ? "ps1" : "bat" remote_name = "C:\\Windows\\Temp\\#{File.basename(tfile.path)}.#{remote_ext}" - if machine_config_ssh.shell.to_s == "powershell" + if shell == "powershell" base_cmd = "powershell -File #{remote_name}" tfile.puts <<-SCRIPT.force_encoding('ASCII-8BIT') Remove-Item #{remote_name} From ee79dd05752ed3a404972af1d0db108759394651 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 4 May 2017 18:48:35 -0700 Subject: [PATCH 2/2] Enable windows guest capabilities using winssh communicator --- plugins/guests/windows/cap/configure_networks.rb | 4 ---- plugins/guests/windows/cap/mount_shared_folder.rb | 2 +- plugins/guests/windows/scripts/mount_volume.ps1.erb | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/plugins/guests/windows/cap/configure_networks.rb b/plugins/guests/windows/cap/configure_networks.rb index a4f4685d9..7c747926e 100644 --- a/plugins/guests/windows/cap/configure_networks.rb +++ b/plugins/guests/windows/cap/configure_networks.rb @@ -9,10 +9,6 @@ module VagrantPlugins @@logger = Log4r::Logger.new("vagrant::guest::windows::configure_networks") def self.configure_networks(machine, networks) - if machine.config.vm.communicator != :winrm - raise Errors::NetworkWinRMRequired - end - @@logger.debug("Networks: #{networks.inspect}") guest_network = GuestNetwork.new(machine.communicate) diff --git a/plugins/guests/windows/cap/mount_shared_folder.rb b/plugins/guests/windows/cap/mount_shared_folder.rb index 9e9f403b9..4a313849b 100644 --- a/plugins/guests/windows/cap/mount_shared_folder.rb +++ b/plugins/guests/windows/cap/mount_shared_folder.rb @@ -34,7 +34,7 @@ module VagrantPlugins vm_provider_unc_path: vm_provider_unc_base + name, }) - if machine.config.vm.communicator == :winrm + if machine.config.vm.communicator == :winrm || machine.config.vm.communicator == :winssh machine.communicate.execute(script, shell: :powershell) else # Convert script to double byte unicode string then base64 encode diff --git a/plugins/guests/windows/scripts/mount_volume.ps1.erb b/plugins/guests/windows/scripts/mount_volume.ps1.erb index b8112d2e3..d8d4285d1 100644 --- a/plugins/guests/windows/scripts/mount_volume.ps1.erb +++ b/plugins/guests/windows/scripts/mount_volume.ps1.erb @@ -28,7 +28,7 @@ if( (Test-Path "$MountPoint") -and (Test-ReparsePoint "$MountPoint") ) } elseif(Test-Path $MountPoint) { - Write-Debug "Mount point already exists and is not a symbolic link" + Write-Error "Mount point already exists and is not a symbolic link" exit 1 }