Netplan configuration is being ignored when deploying a machine

This is a portion of the cloudinit yaml that I give to MAAS when deploying a machine:

network:
  version: 2
  ethernets:
    ens18:
      match:
        macaddress: 'bc:24:11:e5:41:b7'
      dhcp4: true
      dhcp-identifier: mac

But this is getting completely ignored by cloudinit and is setting a static IP on the deployed machine instead:

network:
    ethernets:
        ens18:
            addresses:
            - 192.168.20.3/24
            gateway4: 192.168.20.1
            match:
                macaddress: bc:24:11:e5:41:b7
            mtu: 1500
            nameservers:
                addresses:
                - 192.168.20.100
                search:
                - internal.untouchedwagons.com
                - maas
            set-name: ens18
        ens19:
            match:
                macaddress: bc:24:11:ab:d4:f5
            mtu: 1500
            optional: true
            set-name: ens19
    version: 2

I found this workaround but I shouldn’t have to resort to something like that if “cloud-init will pass Version 2 configuration through to Netplan without modification

Could you provide the entire cloud init script you are using?

Btw if you want the machine tu use DHCP you can edit the interfaces of the machine and set the IP mode to DHCP. No need to use a cloud init script

#cloud-config
# https://cloudinit.readthedocs.io/en/latest/reference/examples.html
packages:
 - qemu-guest-agent
 - openssh-server

users:
  - default
  - name: untouchedwagons
    gecos: untouchedwagons
    primary_group: untouchedwagons
    groups: sudo
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    ssh_import_id:
      - gh:UntouchedWagons

network:
  version: 2
  ethernets:
    ens18:
      match:
        macaddress: 'bc:24:11:e5:41:b7'
      dhcp4: true
      dhcp-identifier: mac

runcmd:
  - [ systemctl, enable, --now, qemu-guest-agent ]
  - [ systemctl, enable, --now, ssh ]

Nope, the cloud-init does not allow to configure the network at that stage. As I suggested in the post you linked, the workaround is to write a bash script to write the netplan config and run netplan apply

Hmm that’s less than ideal in my opinion. The inability to define the networking part of the infrastructure in the code seems like an oversight. But manually configuring the networking does work. Is there an option somewhere to make DHCP the default?

as mentioned in my first reply, you can edit the machine’s interfaces and configure the IP mode from AUTO to DHCP. That way, the interfaces of your machine will be configured to use DHCP and there is no need to use a custom cloud-init script

I meant making DHCP the default for all machines going forward.

nope, that’s not possible atm. You might make this operation as part of your automation, in case you have it

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.