为什么我的 Vagrantfile 即使在 Windows 上被禁用,也会调用 Hyper-V 虚拟机管理程序?

为什么我的 Vagrantfile 即使在 Windows 上被禁用,也会调用 Hyper-V 虚拟机管理程序?

我将 Windows 10 Professional 升级到了最新版本(巴西葡萄牙语):

Microsoft Windows [versão 10.0.18363.592]

此后,当我运行 Vagrantfile 时,甚至使用 Virtualbox 调用配置提供程序并禁用 Hyper-V 资源时都会显示以下消息:

C:\Users\Marlon\Downloads\pipeline (master -> origin)
λ vagrant up                                                 <-using cmder (
Bringing machine 'centos7' up with 'hyperv' provider...
Bringing machine 'debian10' up with 'hyperv' provider...
==> centos7: Verifying Hyper-V is enabled...
The Hyper-V cmdlets for PowerShell are not available! Vagrant
requires these to control Hyper-V. Please enable them in the
"Windows Features" control panel and try again.

如果您在 powershell 中看到以下内容,则表示 Hyper-V 已禁用:

PS C:\Users\Marlon> # Check if Hyper-V is already enabled.
PS C:\Users\Marlon> if($hyperv.State -eq "Enabled") {
>>     Write-Host "Hyper-V is already enabled."
>> } else {
>>     Write-Host "Hyper-V is disabled."
>> }
Hyper-V is disabled.

尝试仅添加 Windows 模块 cmdlet 来查看此站点:

https://www.altaro.com/hyper-v/install-hyper-v-powershell-module/

在此处输入图片描述

当我仅为 Hyper-V 启用 Windows Powershell 模块时,请看一下:

C:\Users\Marlon\Downloads\pipeline (master -> origin)
λ vagrant up
Bringing machine 'centos7' up with 'hyperv' provider...
Bringing machine 'debian10' up with 'hyperv' provider...
==> centos7: Verifying Hyper-V is enabled...
==> centos7: Verifying Hyper-V is accessible...
==> centos7: Importing a Hyper-V instance
    centos7: Creating and registering the VM...
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.

Script: import_vm.ps1
Error:

O Hyper-V não foi instalado no computador 'DESKTOP-GQN4SVI'.

看看我的Vagrant文​​件并看到配置提供程序设置中有一行有关 VirtuaBox 的内容。

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox" do |vb|
     vb.gui = false
     vb.memory = "4096"
     vb.cpus = "4"
  end

  config.vm.define "centos7" do |centos7|
      centos7.vm.box = "centos/7"
      centos7.vm.hostname = "centos-vm"
      centos7.vm.network "public_network", ip: "192.168.0.105"
      centos7.vm.network "forwarded_port", guest: 8080, host: 80
      centos7.vm.provision "shell", run: "always", inline: <<-SHELL
         sudo yum update
         sudo yum -y install wget ntpdate net-tools nano firewalld jenkins apache telnet
         sudo route add default gw 192.168.0.1

         # Install java
         sudo yum -y install epel-release
         sudo yum -y java-1.8.0-openjdk.x86_64
         java -version

         #install ansible
         sudo yum -y install ansible

         sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
         sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
         sudo yum -y install jenkins
         sudo systemctl daemon-reload
         sudo systemctl status jenkins
         sudo systemctl start jenkins
         sudo systemctl status jenkins
         sudo systemctl enable --now jenkins

         # Install docker
         curl -fsSL https://get.docker.com/ | sh
         sudo usermod -aG docker $USER
         sudo systemctl start docker
         sudo systemctl status docker
         sudo systemctl enable docker
         sudo ps -ef | grep dockerd
      SHELL
  end

  config.vm.define "debian10" do |debian10|
      debian10.vm.box = "debian/buster64"
      debian10.vm.hostname = "debian-vm"
      debian10.vm.network "public_network", ip: "192.168.0.106"
      debian10.vm.provision "shell", run: "always", inline: <<-SHELL

         # isntall python with venv
         sudo apt update
         sudo apt -y upgrade
         python3 -V
         sudo apt install -y python3-pip
         sudo apt install build-essential libssl-dev libffi-dev python3-dev
         sudo apt install -y python3-venv
         mkdir environments
         cd environments
         python3.7 -m venv my_env
         ls my_env
         source my_env/bin/activate

         sudo apt install wget ntpdate net-tools nano default-jdk -y
         sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common telnet -y
         sudo route add default gw 192.168.0.1
      SHELL
  end
end

我不知道该如何解决,因为直到看到 BIOS 才知道虚拟化资源是否被禁用,但事实并非如此。

我只想运行vagrant up并调用 VirtualBox 提供程序,而无需调用 Hyper-V,并且没有任何错误消息......

更新第一条评论:

PS C:\WINDOWS\system32> Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All


Path          :
Online        : True
RestartNeeded : False

答案1

安装了 Vagrant 2.2.7 并且现在运行良好!

流浪者版本:

C:\Users\Marlon\Downloads\pipeline (master -> origin)
λ rm -fr .vagrant\

C:\Users\Marlon\Downloads\pipeline (master -> origin)
λ vagrant --version
Vagrant 2.2.7

虚拟盒版本:

C:\Program Files\Oracle\VirtualBox
λ VBoxManage.exe --version
6.1.2r135662

https://github.com/hashicorp/vagrant/blob/v2.2.7/CHANGELOG.md

相关内容