From 8756cbea1b660b084299d2d8e9f66733d6590f58 Mon Sep 17 00:00:00 2001 From: Logan V Date: Wed, 27 Feb 2019 17:42:33 -0600 Subject: [PATCH] Add DIB_APT_MINIMAL_CREATE_INTERFACES toggle Add a DIB_APT_MINIMAL_CREATE_INTERFACES boolean to the debootstrap element which functions identically to DIB_YUM_MINIMAL_CREATE_INTERFACES in the yum-minimal element. This can be used to disable the creation of the /etc/network/interfaces.d/eth[01] dhcp configuration files, which are not needed on systems where cloud-init or other means are used to configure networking. The flag is enabled by default to keep creating the dhcp interface files, maintaining backwards compatibility. Change-Id: I1fdaca8350a5ceefd9e437af4fd000ce6a3ee7f3 --- .../elements/debootstrap/README.rst | 8 +++++++ .../install.d/10-debian-networking | 24 ++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/diskimage_builder/elements/debootstrap/README.rst b/diskimage_builder/elements/debootstrap/README.rst index e0e32ab0..a84006a6 100644 --- a/diskimage_builder/elements/debootstrap/README.rst +++ b/diskimage_builder/elements/debootstrap/README.rst @@ -63,6 +63,14 @@ For further information about ``DIB_DEBIAN_DEBOOTSTRAP_SCRIPT`` , ``DIB_DEBIAN_USE_DEBOOTSTRAP_CACHE`` and ``DIB_DEBOOTSTRAP_EXTRA_ARGS`` please consult "README.rst" of the debootstrap element. +---------- +Networking +---------- + +By default ``/etc/network/interfaces.d/eth[0|1]`` files will be +created and enabled with DHCP networking. If you do not wish this to +be done, set ``DIB_APT_MINIMAL_CREATE_INTERFACES`` to ``0``. + ------------------- Note on ARM systems ------------------- diff --git a/diskimage_builder/elements/debootstrap/install.d/10-debian-networking b/diskimage_builder/elements/debootstrap/install.d/10-debian-networking index d5cdc140..420e7413 100755 --- a/diskimage_builder/elements/debootstrap/install.d/10-debian-networking +++ b/diskimage_builder/elements/debootstrap/install.d/10-debian-networking @@ -24,15 +24,21 @@ set -o pipefail # It would be eversogreat if we didn't need to do crap like this echo $DISTRO_NAME > /etc/hostname -# cloud images expect eth0 and eth1 to use dhcp. -mkdir -p /etc/network/interfaces.d -if ! grep -E -q '^source(|-directory) /etc/network/interfaces.d/\*' /etc/network/interfaces; then - echo "source /etc/network/interfaces.d/*" >> /etc/network/interfaces - echo 'Network configuration set to source /etc/network/interfaces.d/*' -fi -for interface in eth0 eth1; do - cat << EOF | tee /etc/network/interfaces.d/$interface +# If you want eth0 and eth1 created as DHCP based interfaces, enable +# this. You don't want this if systemd is going to call the +# interfaces on the real system something else, or if you're using a +# network-manager like cloud-init, glean or systemd-networkd that will +# handle the interfaces dynamically. +if [[ "${DIB_APT_MINIMAL_CREATE_INTERFACES:-1}" -eq "1" ]]; then + mkdir -p /etc/network/interfaces.d + if ! grep -E -q '^source(|-directory) /etc/network/interfaces.d/\*' /etc/network/interfaces; then + echo "source /etc/network/interfaces.d/*" >> /etc/network/interfaces + echo 'Network configuration set to source /etc/network/interfaces.d/*' + fi + for interface in eth0 eth1; do + cat << EOF | tee /etc/network/interfaces.d/$interface auto $interface iface $interface inet dhcp EOF -done + done +fi