From a98f6e54e7217c6f84996a6b5359b2177b7daecd Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Wed, 4 Mar 2020 00:07:58 +0100 Subject: [PATCH] Make IP address assignment work with libvirt The systemd-networkd script in vmdebootstrap that is used to build the Debian libvirt vagrant boxes is a bit too eager assigning DHCP to network interfaces. This patch changes the network script to only take care of the primary network interface (first non loopback). --- Vagrantfile | 4 +++- change-vmdebootstrap-default-dhcp.sh | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 change-vmdebootstrap-default-dhcp.sh diff --git a/Vagrantfile b/Vagrantfile index 3a03a6c..9c6e103 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,7 +5,7 @@ Vagrant.configure(2) do |config| config.vm.box = "debian/buster64" config.vm.hostname = "gvaldap.local" - config.vm.network "private_network", ip: "172.16.3.3", lxc__bridge_name: 'vlxcbr1' + config.vm.network :private_network, :ip => "172.16.3.3" config.vm.network "forwarded_port", guest: 8000, host: 8001 @@ -16,6 +16,8 @@ Vagrant.configure(2) do |config| libvirt.memory = 1024 end + config.vm.provision :shell, path: "change-vmdebootstrap-default-dhcp.sh" + config.vm.provision :salt do |salt| salt.bootstrap_options = "-x python3" salt.minion_id = "gvaldap" diff --git a/change-vmdebootstrap-default-dhcp.sh b/change-vmdebootstrap-default-dhcp.sh new file mode 100644 index 0000000..384bb39 --- /dev/null +++ b/change-vmdebootstrap-default-dhcp.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +debootstrap_network=/etc/systemd/network/99-dhcp.network + +if grep -q '^Name=\\*' "${debootstrap_network}"; then + primary_nic=$(ls -1 /sys/class/net | grep -v lo |sort | head -1) + sed -i "s/^Name=e\\*/Name=${primary_nic})/" \ + "${debootstrap_network}" + systemctl restart systemd-networkd.service + echo "Changed systemd network configuration" +else + echo "Systemd network configuration has already been changed" +fi