hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.24k stars 4.43k forks source link

Vagrant cannot reconnect to Windows VM (WinRM) that was rebooted by shell provider #10880

Open mbergal opened 5 years ago

mbergal commented 5 years ago

Vagrant version

Vagrant 2.2.4

Host operating system

Windows 10 Pro 1809, build 17763.503

Guest operating system

StefanScherer/windows_2019

Vagrantfile

worker_memory = 4096
worker_cpu_cores = 2

def requiredEnvironmentVariable(name)
  r = ENV[name]
  if r.to_s.strip.empty? then
    raise "Environment variable #{name} is required"
  end
  return r
end

vagrantSmbUsername = requiredEnvironmentVariable("VAGRANT_SMB_USERNAME")
vagrantSmbUsernameNoDomain = vagrantSmbUsername.split("\\").last
vagrantSmbPassword = requiredEnvironmentVariable("VAGRANT_SMB_PASSWORD")

Vagrant.configure("2") do |config|
  puts vagrantSmbUsername
  config.vm.synced_folder ".", "/vagrant", type: "smb",
      smb_password: vagrantSmbPassword, smb_username: vagrantSmbUsername

  config.vm.define "win-worker" do |worker|
    worker.vm.synced_folder ".", "/vagrant", type: "smb",  mount_options: ["vers=3"],
      smb_password: vagrantSmbPassword, smb_username: vagrantSmbUsername
    worker.vm.box = "StefanScherer/windows_2019"
    worker.vm.hostname = "win-worker"
    worker.vm.provider "hyperv" do |hyperv|
      hyperv.vmname = "win-worker"
      hyperv.enable_virtualization_extensions = true
      hyperv.linked_clone = true
      hyperv.memory = worker_memory
      hyperv.cpus = worker_cpu_cores
    end
    worker.vm.network "private_network", bridge: "Default Switch"
    worker.vm.communicator = "winrm"
    worker.winrm.username = "vagrant"
    worker.winrm.password = "vagrant"
    worker.vm.provision "shell", path: './install-docker.ps1', name: "Install Docker", reboot: true
  end
end
param([switch] $Force);

$ErrorActionPreferenece = "Stop"

if ((Test-Path -Path C:\install-docker.done) -and -not $Force) {
    Write-Host "This has already been done"
    exit 0;
}

ls c:/vagrant
Write-Host "Installing Nuget..."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Write-Host "Installing DockerMsftProvider..."
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Write-Host "Installing Docker..."
Install-Package -Name Docker -ProviderName DockerMsftProvider -Force
#Restart-Computer -Force
echo "" > C:\install-docker.done

Debug output

https://gist.github.com/mbergal/242b29c628095e36eb1b3c8a4bd0badd

Expected behavior

Vagrant should have completed successfully.

Actual behavior

INFO interface: error: Vagrant timed out while attempting to connect via WinRM. This usually
means that the VM booted, but there are issues with the WinRM configuration
or network connectivity issues. Please try to `vagrant reload` or
`vagrant up` again.
Vagrant timed out while attempting to connect via WinRM. This usually
means that the VM booted, but there are issues with the WinRM configuration
or network connectivity issues. Please try to `vagrant reload` or
`vagrant up` again.
 INFO interface: Machine: error-exit ["VagrantPlugins::CommunicatorWinRM::Errors::ConnectionTimeout", "Vagrant timed out while attempting to connect via WinRM. This usually\nmeans that the VM booted, but there are issues with the WinRM configuration\nor network connectivity issues. Please try to `vagrant reload` or\n`vagrant up` again."]

Steps to reproduce

  1. Run vagrant on attached files
mbergal commented 5 years ago

https://github.com/hashicorp/vagrant/blob/master/plugins/guests/windows/cap/reboot.rb#L44 is might be a problem since it does not wait for WinRM to become available after reboot.

jacquecosta commented 5 years ago

Any update about this item?