vagrant-libvirt
vagrant-libvirt copied to clipboard
Vagrant ignores values of "ip" in config.vm.network
Describe the bug
I would like to use Vagrant to deploy libvirt virtual machines (a) on a libvirt network created by Vagrant and (b) with predefined static addresses. While the libvirt plugin seems to create the network correctly, the ip setting is ignored. The following Vagrantfile demonstrates the problem:
Vagrant.configure("2") do |config|
config.vm.box = "fedora/36-cloud-base"
config.vm.box_version = "36-20220504.1"
config.vm.provider :libvirt do |libvirt|
libvirt.uri = "qemu:///system"
libvirt.memory = 4096
libvirt.storage :file, :type => 'qcow2'
end
config.vm.define "node1" do |machine|
machine.vm.hostname = "node1"
machine.vm.network :private_network,
:libvirt__network_name => "macvlan-example",
:libvirt__netmask => "255.255.255.0",
:libvirt__host_ip => "192.168.113.1",
:ip => "192.168.113.11"
end
end
The vagrant environment comes up without a problem, but the vm has an address acquired using DHCP rather than the static address requested:
$ vagrant ssh node1
[vagrant@node1 ~]$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:43:35:8c brd ff:ff:ff:ff:ff:ff
altname enp0s7
altname ens7
inet 192.168.113.207/24 brd 192.168.113.255 scope global dynamic noprefixroute eth1
valid_lft 3566sec preferred_lft 3566sec
inet6 fe80::67ec:b241:5c1b:ecdd/64 scope link noprefixroute
valid_lft forever preferred_lft forever
If I set libvirt__dhcp_enabled => false, then eth1 simply is not assigned an ip address.
To Reproduce
(See above)
Expected behavior
I expect the ip option for machine.vm.network to assign the requested ip address to the appropriate network interface.
Versions (please complete the following information)::
- Libvirt version: libvirt-7.6.0-5.fc35.x86_64
- Vagrant version [output of
vagrant version]: Installed Version: 2.2.16 - Vagrant flavour [Upstream or Distro]: distro (Fedora 35)
- Vagrant plugins versions (including vagrant-libvirt) [output of
vagrant plugin list]:- vagrant-libvirt (0.4.1, system)
Debug Log
Attach Output of VAGRANT_LOG=debug vagrant ... --provider=libvirt >vagrant.log 2>&1
A Vagrantfile to reproduce the issue:
(see above)
I've worked around the problem by performing address assignment in the provisioning script instead:
#!/bin/bash
BASEADDR="192.168.113"
PREFIXLEN="24"
NODE="${HOSTNAME:4}"
sudo nmcli c add \
type ethernet \
conn.id eth1 \
ifname eth1 \
ipv4.method manual \
ipv4.address "${BASEADDR}.$(( NODE + 10 ))/${PREFIXLEN}"
sudo nmcli c up eth1
@larsks this is a bug with Vagrant itself, the problem is it is not correctly configuring the private network device, and consequently it is requesting a dhcp address. By default vagrant-libvirt will enable dhcp support for networks created in case you only want some machines to have static addresses, but it expects vagrant to configure the network in the guest for everything after the management network.
While it might be more robust if we were to include the address assignment in the dhcp rules for the network, it just simply masks that vagrant is not configuring additional networks in the guest machine correctly.
Looking upstream I see hashicorp/vagrant#12762 which indicates it is indeed due to a change in behaviour of how networks are configured in Fedora 36.
Closing as won't be fixed here, instead needs to be fixed in vagrant itself.