Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 10 guest not auto-detected #6060

Closed
dafyddj opened this issue Jul 30, 2015 · 8 comments
Closed

Windows 10 guest not auto-detected #6060

dafyddj opened this issue Jul 30, 2015 · 8 comments

Comments

@dafyddj
Copy link
Contributor

dafyddj commented Jul 30, 2015

Vagrant 1.7.4
Mac OS X 10.10.4

Vagrant fails to auto-detect a Windows 10 guest.

DEBUG guest: Trying: windows
DEBUG winrmshell: powershell executing:
            $p = "$Env:SystemRoot"
            if ((Test-Path $p) -and (get-item $p).PSIsContainer) {
              exit 0
            }
            exit 1

if ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }
DEBUG winrmshell: Output: {:data=>[{:stderr=>"#< CLIXML\r\n"}, {:stderr=>"<Objs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\"><Obj S=\"progress\" RefId=\"0\"><TN RefId=\"0\"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N=\"SourceId\">1</I64><PR N=\"Record\"><AV>Preparing m"}, {:stderr=>"odules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>"}], :exitcode=>0}
ERROR warden: Error occurred: The guest operating system of the machine could not be detected!
Vagrant requires this knowledge to perform specific tasks such
as mounting shared folders and configuring networks. Please add
the ability to detect this guest operating system to Vagrant
by creating a plugin or reporting a bug.

Windows 8.1 guest is detected correctly:

DEBUG guest: Trying: windows
DEBUG winrmshell: powershell executing:
            $p = "$Env:SystemRoot"
            if ((Test-Path $p) -and (get-item $p).PSIsContainer) {
              exit 0
            }
            exit 1

if ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }
DEBUG winrmshell: Output: {:data=>[], :exitcode=>0}
 INFO guest: Detected: windows!
@taliesins
Copy link
Contributor

To fix this you need:

From 44df89510752b2ac5a163719b39595332ba8432d Mon Sep 17 00:00:00 2001
From: Taliesin Sisson <[email protected]>
Date: Mon, 3 Aug 2015 19:22:10 +0100
Subject: [PATCH] Don't show progress as the progress stream is written to
 error stream (only for communicate.test scenarios as stderr length is
 checked).

---
 plugins/communicators/winrm/communicator.rb            |  4 ++++
 plugins/guests/windows/guest.rb                        |  2 +-
 plugins/provisioners/chef/provisioner/base.rb          | 18 ++++++++++++------
 plugins/provisioners/chef/provisioner/chef_apply.rb    |  2 +-
 plugins/provisioners/chef/provisioner/chef_client.rb   |  2 +-
 plugins/provisioners/chef/provisioner/chef_solo.rb     | 11 +++++++++--
 plugins/provisioners/chef/provisioner/chef_zero.rb     |  9 ++++++++-
 plugins/provisioners/puppet/provisioner/puppet.rb      |  9 ++++++++-
 .../plugins/communicators/winrm/communicator_test.rb   |  4 ++--
 9 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/plugins/communicators/winrm/communicator.rb b/plugins/communicators/winrm/communicator.rb
index fdb3fe6..18d9ee0 100644
--- a/plugins/communicators/winrm/communicator.rb
+++ b/plugins/communicators/winrm/communicator.rb
@@ -146,6 +146,10 @@ module VagrantPlugins
         command = @cmd_filter.filter(command)
         return false if command.empty?

+        #As we care about the stderr output we must ignore any progress events.
+        #https://connect.microsoft.com/PowerShell/feedback/details/927384/progress-stream-being-sent-to-stderr-in-winrm-responses
+        command = "$ProgressPreference=\"SilentlyContinue\";#{command}"
+
         opts = {
           command:     command,
           elevated:    false,
diff --git a/plugins/guests/windows/guest.rb b/plugins/guests/windows/guest.rb
index 97e607b..e1d5f42 100644
--- a/plugins/guests/windows/guest.rb
+++ b/plugins/guests/windows/guest.rb
@@ -3,7 +3,7 @@ module VagrantPlugins
     class Guest < Vagrant.plugin("2", :guest)
       def detect?(machine)
         # See if the Windows directory is present.
-        machine.communicate.test("test -d $Env:SystemRoot")
+        machine.communicate.test("$ProgressPreference=\"SilentlyContinue\";test-path -d $Env:SystemRoot")
       end
     end
   end
diff --git a/plugins/provisioners/chef/provisioner/base.rb b/plugins/provisioners/chef/provisioner/base.rb
index e0b2b3f..a5deb6b 100644
--- a/plugins/provisioners/chef/provisioner/base.rb
+++ b/plugins/provisioners/chef/provisioner/base.rb
@@ -38,7 +38,7 @@ module VagrantPlugins
           # Checks for the existence of chef binary and error if it
           # doesn't exist.
           if windows?
-            command = "if ((&'#{binary}' -v) -Match 'Chef: *'){ exit 0 } else { exit 1 }"
+            command = "$ProgressPreference=\"SilentlyContinue\";if ((&'#{binary}' -v) -Match 'Chef: *'){ exit 0 } else { exit 1 }"
           else
             command = "sh -c 'command -v #{binary}'"
           end
@@ -68,7 +68,7 @@ module VagrantPlugins
           @machine.communicate.tap do |comm|
             paths.each do |path|
               if windows?
-                comm.sudo("mkdir ""#{path}"" -f")
+                comm.sudo("$ProgressPreference=\"SilentlyContinue\";mkdir ""#{path}"" -f")
               else
                 comm.sudo("mkdir -p #{path}")
                 comm.sudo("chown -h #{@machine.ssh_info[:username]} #{path}")
@@ -117,7 +117,13 @@ module VagrantPlugins

           remote_file = File.join(guest_provisioning_path, filename)
           @machine.communicate.tap do |comm|
-            comm.sudo("rm -f #{remote_file}", error_check: false)
+            if windows?
+              command = "$ProgressPreference=\"SilentlyContinue\";if (test-path '#{remote_file}') {rm '#{remote_file}' -force -recurse}"
+            else
+              command = "rm -f #{remote_file}"
+            end
+            
+            comm.sudo(command, error_check: false)
             comm.upload(temp.path, remote_file)
           end
         end
@@ -140,7 +146,7 @@ module VagrantPlugins
           remote_file = File.join(guest_provisioning_path, "dna.json")
           @machine.communicate.tap do |comm|
             if windows?
-              command = "if (test-path '#{remote_file}') {rm '#{remote_file}' -force -recurse}"
+              command = "$ProgressPreference=\"SilentlyContinue\";if (test-path '#{remote_file}') {rm '#{remote_file}' -force -recurse}"
             else
               command = "rm -f #{remote_file}"
             end
@@ -159,7 +165,7 @@ module VagrantPlugins

           @machine.communicate.tap do |comm|
             if windows?
-              command = "if (test-path ""#{remote_file}"") {rm ""#{remote_file}"" -force -recurse}"
+              command = "$ProgressPreference=\"SilentlyContinue\";if (test-path ""#{remote_file}"") {rm ""#{remote_file}"" -force -recurse}"
             else
               command = "rm -f #{remote_file}"
             end
@@ -173,7 +179,7 @@ module VagrantPlugins
           remote_file = guest_encrypted_data_bag_secret_key_path
           if remote_file
             if windows?
-              command = "if (test-path ""#{remote_file}"") {rm ""#{remote_file}"" -force -recurse}"
+              command = "$ProgressPreference=\"SilentlyContinue\";if (test-path ""#{remote_file}"") {rm ""#{remote_file}"" -force -recurse}"
             else
               command = "rm -f #{remote_file}"
             end
diff --git a/plugins/provisioners/chef/provisioner/chef_apply.rb b/plugins/provisioners/chef/provisioner/chef_apply.rb
index 602c81f..1380ded 100644
--- a/plugins/provisioners/chef/provisioner/chef_apply.rb
+++ b/plugins/provisioners/chef/provisioner/chef_apply.rb
@@ -19,7 +19,7 @@ module VagrantPlugins

           # Reset upload path permissions for the current ssh user
           if windows?
-            @machine.communicate.sudo("mkdir ""#{config.upload_path}"" -f")
+            @machine.communicate.sudo("$ProgressPreference=\"SilentlyContinue\";mkdir ""#{config.upload_path}"" -f")
           else
             @machine.communicate.sudo("mkdir -p #{config.upload_path}")
             @machine.communicate.sudo("chown -R #{user} #{config.upload_path}")
diff --git a/plugins/provisioners/chef/provisioner/chef_client.rb b/plugins/provisioners/chef/provisioner/chef_client.rb
index da44fce..e3edef2 100644
--- a/plugins/provisioners/chef/provisioner/chef_client.rb
+++ b/plugins/provisioners/chef/provisioner/chef_client.rb
@@ -40,7 +40,7 @@ module VagrantPlugins
           path = Pathname.new(guest_client_key_path)

           if windows?
-            @machine.communicate.sudo("mkdir ""#{path.dirname}"" -f")
+            @machine.communicate.sudo("$ProgressPreference=\"SilentlyContinue\";mkdir ""#{path.dirname}"" -f")
           else
             @machine.communicate.sudo("mkdir -p #{path.dirname}")
           end
diff --git a/plugins/provisioners/chef/provisioner/chef_solo.rb b/plugins/provisioners/chef/provisioner/chef_solo.rb
index f3b52f1..0f2fff9 100644
--- a/plugins/provisioners/chef/provisioner/chef_solo.rb
+++ b/plugins/provisioners/chef/provisioner/chef_solo.rb
@@ -207,8 +207,15 @@ module VagrantPlugins
         def verify_shared_folders(folders)
           folders.each do |folder|
             @logger.debug("Checking for shared folder: #{folder}")
-            if [email protected]("test -d #{folder}", sudo: true)
-              raise ChefError, :missing_shared_folders
+
+            if windows?
+              if [email protected]("$ProgressPreference=\"SilentlyContinue\";test-path -d #{folder}")
+                raise ChefError, :missing_shared_folders
+              end              
+            else
+              if [email protected]("test -d #{folder}", sudo: true)
+                raise ChefError, :missing_shared_folders
+              end
             end
           end
         end
diff --git a/plugins/provisioners/chef/provisioner/chef_zero.rb b/plugins/provisioners/chef/provisioner/chef_zero.rb
index 48078a0..e1ef8d3 100644
--- a/plugins/provisioners/chef/provisioner/chef_zero.rb
+++ b/plugins/provisioners/chef/provisioner/chef_zero.rb
@@ -94,7 +94,14 @@ module VagrantPlugins
         def verify_shared_folders(folders)
           folders.each do |folder|
             @logger.debug("Checking for shared folder: #{folder}")
-            if [email protected]("test -d #{folder}", sudo: true)
+
+            if windows?
+              command = "$ProgressPreference=\"SilentlyContinue\";test-path -d #{folder}"
+            else
+              command = "test -d #{folder}"
+            end
+
+            if [email protected](command, sudo: true)
               raise ChefError, :missing_shared_folders
             end
           end
diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb
index f1987db..e5740c0 100644
--- a/plugins/provisioners/puppet/provisioner/puppet.rb
+++ b/plugins/provisioners/puppet/provisioner/puppet.rb
@@ -258,7 +258,14 @@ module VagrantPlugins
         def verify_shared_folders(folders)
           folders.each do |folder|
             @logger.debug("Checking for shared folder: #{folder}")
-            if [email protected]("test -d #{folder}", sudo: true)
+
+            if windows?
+              command = "test-path -d #{folder}"
+            else
+              command = "test -d #{folder}"
+            end
+
+            if [email protected](command, sudo: true)
               raise PuppetError, :missing_shared_folders
             end
           end
diff --git a/test/unit/plugins/communicators/winrm/communicator_test.rb b/test/unit/plugins/communicators/winrm/communicator_test.rb
index ceea098..6d7fdf8 100644
--- a/test/unit/plugins/communicators/winrm/communicator_test.rb
+++ b/test/unit/plugins/communicators/winrm/communicator_test.rb
@@ -83,13 +83,13 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
     it "returns true when exit code is zero" do
       output = { exitcode: 0, data:[{ stderr: '' }] }
       expect(shell).to receive(:powershell).with(kind_of(String)).and_return(output)
-      expect(subject.test("test -d c:/windows")).to be_true
+      expect(subject.test("test-path -d c:/windows")).to be_true
     end

     it "returns false when exit code is non-zero" do
       output = { exitcode: 1, data:[{ stderr: '' }] }
       expect(shell).to receive(:powershell).with(kind_of(String)).and_return(output)
-      expect(subject.test("test -d /tmp/foobar")).to be_false
+      expect(subject.test("test-path -d /tmp/foobar")).to be_false
     end

     it "returns false when stderr contains output" do
-- 
1.9.5.msysgit.0

@phromo
Copy link

phromo commented Aug 4, 2015

Experienced this same error on Windows 2012 R2 after installing WMF 5 April 2015 from http://www.microsoft.com/en-us/download/details.aspx?id=44987

taliesins fixes in his above comment (winrm-fs latest + patch) solved my problem.

@StefanScherer
Copy link
Contributor

@sethvargo I think the label host/windows is misleading, as the host is OSX, but the guest is Windows 10. I also struggle spinning up Windows 10 Vagrant boxes on my Mac and investigated the problem a little bit.

I can confirm that the problem is fixed with the Ruby gem winrm-fs 0.2.2.

My setup is:
Host OSX 10.10.4, Vagrant 1.7.4 + winrm-fs 0.2.2, spinning up and provisioning a Windows 10 guest.

This will probably fix #6055 as well.

@StefanScherer
Copy link
Contributor

This worked for me as a user of Vagrant to update the winrm-fs gem to version 0.2.2:

$ vagrant --version
Vagrant 1.7.4

$ vagrant plugin install winrm-fs
Installing the 'winrm-fs' plugin. This can take a few minutes...
Installed the plugin 'winrm-fs (0.2.2)'!

Would be nice if the winrm-fs gem will be already installed in the next Vagrant release.

@legleux
Copy link

legleux commented Sep 4, 2015

I'm having this problem too.
How do I even go about applying this patch?

@phromo
Copy link

phromo commented Sep 4, 2015

  1. https://duckduckgo.com/?q=apply+patch ... > https://docs.moodle.org/dev/How_to_apply_a_patch
  2. locate plugins/provisioners/puppet/provisioner/puppet.rb on your system
  3. cd that folder (where ls plugins => plugins)
  4. apply the patch
  5. update winrm-fs by vagrant plugin install winrm-fs

@mitchellh
Copy link
Contributor

This should all be fixed in 1.8!

@ghost
Copy link

ghost commented Jan 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jan 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants