admin管理员组

文章数量:1208155

I'm using the same Vagrantfile on two machines: Windows 7 with VirtualBox 6.1.50 and Linux Mint 22 with VirtualBox 7.1.4. Vagrant 2.4.3 on both. On the Windows host vagrant up brings up the VM just fine. On the Linux host, however, it fails:

Bringing machine 'ansible-test' up with 'virtualbox' provider...
==> ansible-test: Box 'ubuntu/jammy64' could not be found. Attempting to find and install...
    ansible-test: Box Provider: virtualbox
    ansible-test: Box Version: >= 0
==> ansible-test: Loading metadata for box 'ubuntu/jammy64'
    ansible-test: URL: 
==> ansible-test: Adding box 'ubuntu/jammy64' (v20241002.0.0) for provider: virtualbox
    ansible-test: Downloading: .0.0/providers/virtualbox/unknown/vagrant.box
==> ansible-test: Successfully added box 'ubuntu/jammy64' (v20241002.0.0) for 'virtualbox'!
==> ansible-test: Importing base box 'ubuntu/jammy64'...
==> ansible-test: Matching MAC address for NAT networking...
==> ansible-test: Checking if box 'ubuntu/jammy64' version '20241002.0.0' is up to date...
==> ansible-test: Setting the name of the VM: ansible-test
==> ansible-test: Clearing any previously set network interfaces...
==> ansible-test: Preparing network interfaces based on configuration...
    ansible-test: Adapter 1: nat
    ansible-test: Adapter 2: hostonly
==> ansible-test: Forwarding ports...
    ansible-test: 22 (guest) => 2222 (host) (adapter 1)
==> ansible-test: Running 'pre-boot' VM customizations...
==> ansible-test: Booting VM...
==> ansible-test: Waiting for machine to boot. This may take a few minutes...
    ansible-test: SSH address: 127.0.0.1:2222
    ansible-test: SSH username: vagrant
    ansible-test: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

It gets stuck for a long time after "SSH auth method: private key". If open the VM console during that time I can see that the host-only NIC is not connected and does not have an IP. ip a shows

3: enp0s: <BROADCAST, MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000

There is also no /etc/netplan/50-vagrant.yml file, which is created when running on the Windows host (although this might happen later in the process?).

I tried running with --debug and cannot see any issue in there. It seems to be configuring the NIC:

 INFO network: Network slot 2. Type: hostonly.
 INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "list", "bridgedifs"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
DEBUG network: Normalized configuration: {:adapter_ip=>"192.168.20.1", :auto_config=>true, :ip=>"192.168.20.101", :mac=>nil, :name=>"vboxnet0", :netmask=>"255.255.255.0", :nic_type=>nil, :type=>:static, :adapter=>2}
 INFO network: Searching for matching hostonly network: 192.168.20.101
 INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "list", "hostonlyifs"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
DEBUG network: Adapter configuration: {:adapter=>2, :hostonly=>"vboxnet0", :mac_address=>nil, :nic_type=>nil, :type=>:hostonly}
 INFO network: Enabling adapters...
 INFO interface: output: Preparing network interfaces based on configuration...
 INFO interface: output: ==> ansible-test: Preparing network interfaces based on configuration...
 INFO interface: detail: Adapter 1: nat
 INFO interface: detail:     ansible-test: Adapter 1: nat
 INFO interface: detail: Adapter 2: hostonly
 INFO interface: detail:     ansible-test: Adapter 2: hostonly
 INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "modifyvm", "819b7338-c1c1-43fc-bf38-5e936b26612e", "--nic1", "nat", "--nic2", "hostonly", "--hostonlyadapter2", "vboxnet0", "--cableconnected2", "on"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0

Vagrantfile:

Vagrant.require_version ">= 2.0.4"

if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
  vbox_adapter_name = "VirtualBox Host-Only Ethernet Adapter"
  vboxmanage_path = "C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe"
  unless File.exist?(vboxmanage_path)
    vboxmanage_path = "C:\\Program Files\\VirtualBox\\VBoxManage.exe"
  end
else
  vbox_adapter_name = "vboxnet0"
  vboxmanage_path = "VBoxManage" # Assume it's in the path on Linux
end

Vagrant.configure(2) do |config|
  vms = ["ansible-test"]

  vms.each_with_index do |name, i|
    config.vm.define name do |node|
      node.vm.hostname = name
      start_ip = 101

      node.vmwork "private_network", ip: "192.168.20.#{start_ip + i}", name: vbox_adapter_name
    end
  end

  config.vm.box = "ubuntu/jammy64"

  config.vm.provider "virtualbox" do |vb|
    vb.name = "ansible-test"
    vb.gui = false
    vb.memory = "1024"
    vb.cpus = 2
    vb.customize ["modifyvm", :id, "--natnet1", "192.168.15.0/24"]
    vb.customize ["modifyvm", :id, "--graphicscontroller", "vmsvga"]
  end
end

How do I fix this?

本文标签: vagrant up fails to SSH on Linux hostbut works on Windows hostStack Overflow