发放带有Vagrant的Windows虚拟机无法执行远程WinRM命令



我试图在现有的Vagrant盒子上安装一些基本的工具,但是我的shell命令失败,因为Vagrant不能执行WinRM命令。

得到以下输出:

❯ vagrant up --provider vmware_workstation
Bringing machine 'default' up with 'vmware_workstation' provider...
==> default: Cloning VMware VM: 'StefanScherer/windows_2019'. This can take some time...
==> default: Verifying vmnet devices are healthy...
==> default: Preparing network adapters...
==> default: Fixed port collision for 3389 => 3389. Now on port 2200.
==> default: Starting the VMware VM...
==> default: Waiting for the VM to receive an address...
==> default: Forwarding ports...
default: -- 3389 => 2200
default: -- 5985 => 55985
default: -- 5986 => 55986
default: -- 22 => 2222
==> default: Waiting for machine to boot. This may take a few minutes...
default: WinRM address: 127.0.0.1:55985
default: WinRM username: vagrant
default: WinRM execution_time_limit: PT2H
default: WinRM transport: negotiate
An error occurred executing a remote WinRM command.
Shell: Cmd
Command: hostname
Message: [WSMAN ERROR CODE: 2147942421]: <f:WSManFault Code='2147942421' Machine='127.0.0.1' xmlns:f='http://schemas.microsoft.com/wbem/wsman/1/wsmanfault'><f:Message><f:ProviderFault path='%systemroot%system32winrscmd.dll' provider='Shell cmd plugin'>The device is not ready. </f:ProviderFault></f:Message></f:WSManFault>

当我看了看虚拟机,它有"你想信任这个网络吗?"弹出打开。当我遵循这个过程并接受提示时,供应会按照预期继续进行,但我真的不想呆在那里等待Windows弹出并单击按钮。有没有一种方法可以让它自动化呢?

这是我正在使用的Vagrantfile:

Vagrant.configure("2") do |config|
config.vm.box = "StefanScherer/windows_2019"
# Setup environment.
config.vm.provision "shell", path: "provision.ps1"
# PowerShell must be reloaded, so we'll open up a new instance.
config.vm.provision "shell", inline: "choco feature enable -n allowGlobalConfirmation"
config.vm.provision "shell", inline: "choco install firefox azure-cli terraform"
config.vm.provider "vmware_workstation" do |v|
v.gui = true
end
end

没关系。经过更多的测试,我发现我只需要在Vagrantfile中增加WinRM连接的重试次数:

config.winrm.max_tries = 300 # default is 20
config.winrm.retry_delay = 2 #seconds. This is the defaul value and just here for documentation.

将超时时间设置为10分钟,在我的机器上启动Windows虚拟机绰绰有余。然而,默认的40s通常是不够的,并且只能有时正确地配置我的VM。

希望对大家有所帮助。

最新更新