Setting hostname fails on Windows 7 Enterprise x86 Vagrant box #33

Closed
warrickcustomhomes opened this Issue Dec 7, 2012 · 4 comments

Comments

Projects
None yet
4 participants
@warrickcustomhomes

In trying to automatically set the hostname of a Windows 7 Enterprise x86 Vagrant box via the config.vm.host_name = 'testvm' directive, I get the following error that halts the bootstrap process.

ERROR:
Description = Invalid query

When I enable Vagrant logging, I see the following:

DEBUG virtualbox_4_1:   - [1, "rdp", 3390, 3389]
DEBUG virtualbox_4_1:   - [1, "ssh", 2222, 22]
DEBUG virtualbox_4_1:   - [1, "winrm", 5985, 5985]
 INFO winrm: Connecting to WinRM: localhost:5985
DEBUG winrm: WinRM Trying to connect
 INFO winrm: Execute: wmic computersystem where name="%COMPUTERNAME%" call rename name="testvm"
ERROR:
Description = Invalid query
DEBUG winrm: 1
DEBUG winrm: wmic computersystem where name="%COMPUTERNAME%" call rename name="testvm" EXIT STATUS 1

If I run the command as printed above in the Cygwin shell, I get the following result (and I get the same result when I use cmd /c to run the command).

ERROR:
Description = Invalid query

However, if I run the command in the Windows shell (as an Administrator) I get the following result.

Executing (\\VAGRANT-WIN7\ROOT\CIMV2:Win32_ComputerSystem.Name="VAGRANT-WIN7")->rename()
Method execution successful.
Out parameters:
Instance of __PARAMETERS
{
            ReturnValue = 0;
};

So, it seems like the command being executed by Vagrant is correct... any ideas what's going on?

@dpetzel

This comment has been minimized.

Show comment Hide comment
@dpetzel

dpetzel Jan 25, 2013

FWIW, I have the same issue using Windows 2008 R2 boxes. I don't have much to offer as to whats going on, but I'm working around the issue by not setting the hostname in my Vagrantfile (obviously not the desired end goal). I'm mostly posting just to indicate that your not alone with this issue.

dpetzel commented Jan 25, 2013

FWIW, I have the same issue using Windows 2008 R2 boxes. I don't have much to offer as to whats going on, but I'm working around the issue by not setting the hostname in my Vagrantfile (obviously not the desired end goal). I'm mostly posting just to indicate that your not alone with this issue.

@spudnic

This comment has been minimized.

Show comment Hide comment
@spudnic

spudnic Mar 9, 2013

Other folks have also run into the problem of amd64 windows boxes as well, hh/windows-fromscratch#4

spudnic commented Mar 9, 2013

Other folks have also run into the problem of amd64 windows boxes as well, hh/windows-fromscratch#4

@pmorton

This comment has been minimized.

Show comment Hide comment
@pmorton

pmorton Mar 22, 2013

Contributor

Does this repro using the winrm gem directly?

require 'winrm'
endpoint = 'http://localhost:5985/wsman'
winrm = WinRM::WinRMWebService.new(endpoint, :plaintext, :user => 'vagrant', :pass => 'vagrant', :basic_auth_only => true)
winrm.cmd('wmic computersystem where name="%COMPUTERNAME%" call rename name="testvm"') do |stdout, stderr|
  STDOUT.print stdout
  STDERR.print stderr
end

I just ran this command locally an cannot repro. Here is what I get when I run. This may well be a vagrant-windows bug. (Coincidentally I manage that gem too) If you cannot repro here, would you mind moving the bug over to the vagrant-windows gem?

Executing (\\VAGRANT-2008R2\ROOT\CIMV2:Win32_ComputerSystem.Name="VAGRANT-2008R2")->rename()
Method execution successful.

Out Parameters:
instance of __PARAMETERS
{
    ReturnValue = 0;
};
 => {:data=>[{:stdout=>"Executing (\\\\VAGRANT-2008R2\\ROOT\\CIMV2:Win32_ComputerSystem.Name=\"VAGRANT-2008R2\")->rename()\r\r\n"}, {:stdout=>"Method execution successful.\r\r\n"}, {:stderr=>"\r\n"}, {:stdout=>"Out Parameters:\r\ninstance of __PARAMETERS\r\n{\r\n\tReturnValue = 0;\r\n};\r\n"}], :exitcode=>0}
Contributor

pmorton commented Mar 22, 2013

Does this repro using the winrm gem directly?

require 'winrm'
endpoint = 'http://localhost:5985/wsman'
winrm = WinRM::WinRMWebService.new(endpoint, :plaintext, :user => 'vagrant', :pass => 'vagrant', :basic_auth_only => true)
winrm.cmd('wmic computersystem where name="%COMPUTERNAME%" call rename name="testvm"') do |stdout, stderr|
  STDOUT.print stdout
  STDERR.print stderr
end

I just ran this command locally an cannot repro. Here is what I get when I run. This may well be a vagrant-windows bug. (Coincidentally I manage that gem too) If you cannot repro here, would you mind moving the bug over to the vagrant-windows gem?

Executing (\\VAGRANT-2008R2\ROOT\CIMV2:Win32_ComputerSystem.Name="VAGRANT-2008R2")->rename()
Method execution successful.

Out Parameters:
instance of __PARAMETERS
{
    ReturnValue = 0;
};
 => {:data=>[{:stdout=>"Executing (\\\\VAGRANT-2008R2\\ROOT\\CIMV2:Win32_ComputerSystem.Name=\"VAGRANT-2008R2\")->rename()\r\r\n"}, {:stdout=>"Method execution successful.\r\r\n"}, {:stderr=>"\r\n"}, {:stdout=>"Out Parameters:\r\ninstance of __PARAMETERS\r\n{\r\n\tReturnValue = 0;\r\n};\r\n"}], :exitcode=>0}
@pmorton

This comment has been minimized.

Show comment Hide comment
@pmorton

pmorton May 3, 2013

Contributor

@scrapcoder The way that we have fixed this in other gems is to use cmd instead of powershell. Apparently wmic has different syntax under each shell.

Contributor

pmorton commented May 3, 2013

@scrapcoder The way that we have fixed this in other gems is to use cmd instead of powershell. Apparently wmic has different syntax under each shell.

@pmorton pmorton closed this May 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment