ppggff / vagrant-qemu

Use Vagrant to manage machines using QEMU. Test with Apple Silicon / M1 and CentOS aarch64 image
MIT License
431 stars 35 forks source link

QEMU provider doesn't support any of the Vagrant high-level network configurations #8

Closed 825i closed 2 years ago

825i commented 2 years ago
==> default: Warning! The QEMU provider doesn't support any of the Vagrant
==> default: high-level network configurations (`config.vm.network`). They
==> default: will be silently ignored.

So having this in the examples/readme.md isn't really appropriate because these flags in the Vagrantfile are dropped.

ppggff commented 2 years ago

All features listed in the examples/readme.md are works. I think "high-level network" may be the bridge like network?

tdriley commented 2 years ago

I had this warning also, even when removing all config.vm.network options in Vagrantfile until the only one was

config.vm.network "forwarded_port", guest: 80, host: 60080

The process then errors with

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.
ppggff commented 2 years ago

I had this warning also, even when removing all config.vm.network options in Vagrantfile until the only one was

config.vm.network "forwarded_port", guest: 80, host: 60080

The process then errors with

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.

Please provide your Vagrantfile? The "Timed out" issue may caused by the box itself.

tdriley commented 2 years ago

@ppggff I think you are correct. Using a different Vagrant box with the same network configurations, the same warning was displayed but the box did load.

ppggff commented 2 years ago

@tdriley Yes, this warning may related to bridge like network, forwarded_ports is fine

dedenf commented 1 year ago

hi All, sorry to comment on this topic again, my issue a bit related to this issue, using above solution did not solved my problem, if we have a multiple machine configuration on the vagrantfile, it always says that the port already being used (by other defined machine on the vagrantfile).

sorry if this question already being asked

MuhammadElsaeed commented 5 months ago

hi All, sorry to comment on this topic again, my issue a bit related to this issue, using above solution did not solved my problem, if we have a multiple machine configuration on the vagrantfile, it always says that the port already being used (by other defined machine on the vagrantfile).

sorry if this question already being asked

+1

ppggff commented 5 months ago

@dedenf @MuhammadElsaeed Please provide the details error?

MuhammadElsaeed commented 5 months ago

@dedenf @MuhammadElsaeed Please provide the details error?

This is the full logs:

Bringing machine 'ansible1' up with 'qemu' provider...
Bringing machine 'ansible2' up with 'qemu' provider...
Bringing machine 'ansible3' up with 'qemu' provider...
==> ansible3: Checking if box 'perk/ubuntu-2204-arm64' version '20230712' is up to date...
==> ansible1: Checking if box 'perk/ubuntu-2204-arm64' version '20230712' is up to date...
==> ansible1: Importing a QEMU instance
    ansible1: Creating and registering the VM...
==> ansible2: Checking if box 'perk/ubuntu-2204-arm64' version '20230712' is up to date...
    ansible1: Successfully imported VM
==> ansible2: Importing a QEMU instance
    ansible2: Creating and registering the VM...
==> ansible1: Warning! The QEMU provider doesn't support any of the Vagrant
==> ansible1: high-level network configurations (`config.vm.network`). They
==> ansible1: will be silently ignored.
==> ansible1: Starting the instance...
    ansible2: Successfully imported VM
==> ansible1: Waiting for machine to boot. This may take a few minutes...
==> ansible2: An error occurred. The error will be shown after all tasks complete.
    ansible1: SSH address: 127.0.0.1:50022
    ansible1: SSH username: vagrant
    ansible1: SSH auth method: private key
==> ansible3: Importing a QEMU instance
    ansible3: Creating and registering the VM...
    ansible3: Successfully imported VM
==> ansible3: An error occurred. The error will be shown after all tasks complete.
    ansible1: Warning: Connection reset. Retrying...
    ansible1: Warning: Remote connection disconnect. Retrying...
    ansible1: 
    ansible1: Vagrant insecure key detected. Vagrant will automatically replace
    ansible1: this with a newly generated keypair for better security.
    ansible1: 
    ansible1: Inserting generated public key within guest...
    ansible1: Removing insecure key from the guest if it's present...
    ansible1: Key inserted! Disconnecting and reconnecting using new SSH key...
==> ansible1: Machine booted and ready!
==> ansible1: Setting hostname...
An error occurred while executing multiple actions in parallel.
Any errors that occurred are shown below.

An error occurred while executing the action on the 'ansible2'
machine. Please handle this error then try again:

Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 50022 is already in use
on the host machine.

To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 22, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.

An error occurred while executing the action on the 'ansible3'
machine. Please handle this error then try again:

Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 50022 is already in use
on the host machine.

To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 22, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.

And this is my Vagrantfile:

Vagrant.configure("2") do |config|
    # Use QEMU as the provider
    config.vm.provider "qemu" do |qe|
    end

    # ansible1 VM (Ubuntu)
    config.vm.define "ansible1" do |ansible1|
      ansible1.vm.box = "perk/ubuntu-2204-arm64"
      ansible1.vm.hostname = "ansible1"
      ansible1.vm.network "forwarded_port", guest: 22, host: 5022
      ansible1.vm.network "private_network", type: "dhcp"
    end

  #   # Node VM 1 (Ubuntu)
    config.vm.define "ansible2" do |ansible2|
      ansible2.vm.box = "perk/ubuntu-2204-arm64"
      ansible2.vm.hostname = "ansible2"
      ansible2.vm.network "forwarded_port", guest: 22, host: 5023
      ansible2.vm.network "private_network", type: "dhcp"
    end

    # Node VM 2 
    config.vm.define "ansible3" do |ansible3|
      ansible3.vm.box = "perk/ubuntu-2204-arm64"
      ansible3.vm.hostname = "ansible3"
      ansible3.vm.network "forwarded_port", guest: 22, host: 5024
      ansible3.vm.network "private_network", type: "dhcp"
    end
  end

Only the first vm is up, but the other 2 VMs can not be spawned. vagrant status output:

  Current machine states:

ansible1                  running (qemu)
ansible2                  stopped (qemu)
ansible3                  stopped (qemu)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

My machine is running apple m3 chip.

ppggff commented 5 months ago

I think the 'ssh_port' may have a higher priority here, please try to config 'ssh_port' for each vm instead of forwarded_port. For example:

  config.vm.define "n1" do |n1|
    n1.vm.box = "generic/centos8"
    n1.vm.provider "qemu" do |qe|
      qe.ssh_port = 50023
    end
  end

  config.vm.define "n2" do |n2|
    n2.vm.box = "generic/centos8"
    n2.vm.provider "qemu" do |qe|
      qe.ssh_port = 50024
    end
  end
MuhammadElsaeed commented 5 months ago

same error. It tries to configure port 50022 for all the 3 VMs no matter the configuration I gave, so the first VM starts and the other 2 can not started due to port collisions.

ppggff commented 5 months ago

same error. It tries to configure port 50022 for all the 3 VMs no matter the configuration I gave, so the first VM starts and the other 2 can not started due to port collisions.

What's the Vagrantfile file now?

MuhammadElsaeed commented 5 months ago

same error. It tries to configure port 50022 for all the 3 VMs no matter the configuration I gave, so the first VM starts and the other 2 can not started due to port collisions.

What's the Vagrantfile file now?

Vagrant.configure("2") do |config|
    # Use QEMU as the provider
    config.vm.provider "qemu" do |qe|
      # Optional: Customize the QEMU provider here if needed
    end

    # ansible1 VM (Ubuntu)
    config.vm.define "ansible1" do |ansible1|
      ansible1.vm.box = "perk/ubuntu-2204-arm64"
      ansible1.vm.hostname = "ansible1"
    #   ansible1.vm.network "private_network", ip: "192.168.50.20"
      ansible1.vm.provider "qemu" do |qe|
        qe.ssh.port = 5022
      end
    end

    # ansible2 VM (Ubuntu)
    config.vm.define "ansible2" do |ansible2|
      ansible2.vm.box = "perk/ubuntu-2204-arm64"
      ansible2.vm.hostname = "ansible2"
    #   ansible2.vm.network "private_network", ip: "192.168.50.21"
      ansible2.vm.provider "qemu" do |qe|
        qe.ssh.port = 5023
      end
    end

    # ansible3 VM (Ubuntu)
    config.vm.define "ansible3" do |ansible3|
      ansible3.vm.box = "perk/ubuntu-2204-arm64"
      ansible3.vm.hostname = "ansible3"
    #   ansible3.vm.network "private_network", ip: "192.168.50.22"
      ansible3.vm.provider "qemu" do |qe|
        qe.ssh.port = 5024
      end
    end
  end
ppggff commented 5 months ago

The ssh port config should be "ssh_port", not "ssh.port".