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

vagrant hangs settings hostname on windows #5742

Closed
tcuthbert opened this issue May 22, 2015 · 8 comments
Closed

vagrant hangs settings hostname on windows #5742

tcuthbert opened this issue May 22, 2015 · 8 comments

Comments

@tcuthbert
Copy link

Hey I'm running OSX and vagrant version 1.7.2
When I explicitly set the hostname in my Vagrantfile, my windows guest hits an exception and I'm unable to perform tasks like, opening powershell or control panel without an insufficient memory exception.

When I comment out the hostname line, everything appears to work again.

Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.box = "eval-win2012r2-standard-nocm-1.0.4"
  #config.hostmanager.enabled = true
  #config.hostmanager.manage_host = true
  #config.hostmanager.ignore_private_ip = false
  #config.hostmanager.include_offline = true
  config.vm.define 'example-box' do |node|
    node.vm.guest = :windows
    node.vm.hostname = 'example-box-hostname'
    #node.vm.network :private_network, ip: '192.168.42.42'
    #node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)
  end
end

Debug:

DEBUG winrmshell: powershell executing:
if ([System.Net.Dns]::GetHostName() -eq 'example-box-hostname') { exit 0 } exit 1
if ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }
DEBUG winrmshell: Output: {:data=>[], :exitcode=>1}
DEBUG winrmshell: powershell executing:
            try
            {
              $computer = Get-WmiObject -Class Win32_ComputerSystem
              $computer.rename("example-box-hostname")

              Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname"
              Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname"

              New-PSDrive -name HKU -PSProvider "Registry" -Root "HKEY_USERS"

              Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\Computername" -name "Computername" -value "example-box-hostname"
              Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername" -name "Computername" -value "example-box-hostname"
              Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname" -value "example-box-hostname"
              Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname" -value  "example-box-hostname"
              Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "AltDefaultDomainName" -value "example-box-hostname"
              Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "DefaultDomainName" -value "example-box-hostname"
              Set-ItemProperty -path "HKCU:\Volatile Environment" -name "LOGONSERVER" -value "example-box-hostname"
              [Environment]::SetEnvironmentVariable("COMPUTERNAME", "example-box-hostname", "User")

              exit 0
            }
            catch
            {
              exit -1
            }

if ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }
DEBUG winrmshell: Output: {:data=>[{:stdout=>"\r\n"}, {:stdout=>"\r\n"}, {:stdout=>"__GENUS          : 2"}, {:stdout=>"\r\n__CLASS          : __PARAMETERS\r\n__SUPERCLASS     : \r\n__DYNASTY        : __PARAMETERS\r\n__RELPATH        : \r\n__PROPERTY_COUNT : 1\r\n__DERIVATION     : {}\r\n__SERVER         : \r\n__NAMESPACE      : \r\n__PATH           : \r\nReturnValue      : 0\r\nPSComputerName   : \r\n\r\n"}, {:stdout=>"CurrentLocation : "}, {:stdout=>"\r\nName            : HKU\r\nProvider        : Microsoft.PowerShell.Core\\Registry\r\nRoot            : HKEY_USERS\r\nDescription     : \r\nCredential      : System.Management.Automation.PSCredential\r\nDisplayRoot     : \r\nUsed            : \r\nFree            : \r\n\r\n"}], :exitcode=>0}

...

hostname
if ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }
 INFO winrmshell: Attempting to connect to WinRM...
 INFO winrmshell:   - Host: 127.0.0.1
 INFO winrmshell:   - Port: 5985
 INFO winrmshell:   - Username: vagrant
 INFO retryable: Retryable exception raised: #<WinRM::WinRMHTTPTransportError: Bad HTTP response returned from server (500).>
DEBUG winrmshell: powershell executing:
hostname
if ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }
 INFO retryable: Retryable exception raised: #<WinRM::WinRMHTTPTransportError: Bad HTTP response returned from server (500).>

@StefanScherer
Copy link
Contributor

@tcuthbert I'm also using Vagrant 1.7.2 on OSX with both VMware Fusion and VirtualBox with Windows guests and can confirm that setting the hostname works.

For WinRM some settings are needed in the Windows guest to have eg. enough memory for the remote processes. Have a look at https://github.com/boxcutter/windows/blob/master/floppy/install-winrm.cmd#L55

I had a long and colorful discussion with @ferventcoder at his Chocolatey repo in issue chocolatey/choco#277 as the provision scripts sometimes worked and sometimes not.

BTW: Vagrant 1.7.3 will have the old way to set the hostname for windows guests and have a reboot #5261

@tcuthbert
Copy link
Author

Hey Stefen,

I am building my windows boxes through the virtualbox packer provider.
The boxes I'm using are built from the boxcutter repo so should have the
memory set :/ Can you post any tweakings you personally have made to get it
working? I'll explore tweaking those winrm memory settings.

Regards,

Thomas Cuthbert

On Fri, May 22, 2015 at 1:48 PM, Stefan Scherer notifications@github.com
wrote:

@tcuthbert https://github.com/tcuthbert I'm also using Vagrant 1.7.2 on
OSX with both VMware Fusion and VirtualBox with Windows guests and can
confirm that setting the hostname works.

For WinRM some settings are needed in the Windows guest to have eg. enough
memory for the remote processes. Have a look at
https://github.com/boxcutter/windows/blob/master/floppy/install-winrm.cmd#L55

I had a long and colorful discussion with @ferventcoder
https://github.com/ferventcoder at his Chocolatey repo in issue
chocolatey/choco#277 chocolatey/choco#277 as
the provision scripts sometimes worked and sometimes not.

BTW: Vagrant 1.7.3 will have the old way to set the hostname for windows
guests and have a reboot #5261
#5261


Reply to this email directly or view it on GitHub
#5742 (comment).

@StefanScherer
Copy link
Contributor

@tcuthbert I personally use the packer-windows baseboxes for a long time as they have the Windows Update script we need at work. Haven't tried the boxcutter/windows for months, but their settings winrm settings indeed look good.

@tcuthbert
Copy link
Author

@StefanScherer I'm having the same issues with upstream packer-windows. I couldn't get it to work by manually setting the winrm shell mem to 2048 so I'm going to try and generate a fresh box with it set to 4096.

@tcuthbert
Copy link
Author

After tweaking the memory value and rebuilding a new box, still having the same issues.

@tcuthbert
Copy link
Author

This can be closed. Turns out the issue was caused by having hyphens in the hostname.

@erhudy
Copy link

erhudy commented Jun 12, 2015

For what it's worth, this is currently tanking a Vagrant build of mine on Windows (hyphens in the hostname causing vagrant up to get stuck at Setting hostname...). Has that been raised as a separate issue?

@feliksik
Copy link

note #5835, and the fact that the lease pool of your hypervisor (in my case vmware) may be full. So double-check if the ip address of the hanging VM does not already occur in your vagrant inventory file for some other machine.

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

No branches or pull requests

4 participants