Switching to Ubuntu 18.04 results in unbootable AMIs (waiting for network)

We have a pipeline for building Ubuntu 16.04 images using packer - works great - but when we tried to switch to 18.04 or 20.04 - the resulting AMIs are having trouble getting network when they boot - resulting in instances stuck in “waiting for network” limbo - there must have been something changed between 16.04 and 18.04 - but I am not sure what. Anyone run into this?

Startup console is full of messages like:

A start job is running for Wait for…k to be Configured (2s / no limit)

I have removed most of our provisioning steps, and we are still seeing this

If you are using DHCP it could be something related to the switch to netplan (foo).

I’ve done this in my provisioner:

echo -e "      dhcp-identifier: mac" >> /etc/netplan/01-netcfg.yaml
netplan apply

I just don’t know exactly what the error was.

Interfaces are renamed from ethX to ensXXX. Maybe something related to this one?
You can switch back to the original nic names by using

sed -i '/GRUB_CMDLINE_LINUX/s/""/"net.ifnames=0 biosdevname=0 elevator=noop"/g' /etc/default/grub
sed -i '/ens192/s/ens192/eth0/g' /etc/netplan/01-netcfg.yaml
netplan apply

(if ens192 is the new nic name generated by Ubuntu).

Maybe you’ll have any more log output using PACKER_LOG=1 packer build… ?

Yeah, netplan is suspect #1 - but it is my understanding that the /etc/netplan/ file is populated by cloud-init

To be clear, packer runs fine, it is that the AMI produced by packer is not working afterwards

Not 100% sure, but it looks like it is caused by deletion of /etc/machine-id - which should be the right thing to do, but things started to work when I truncated it instead of deleting it… really odd, docs claim deleting it is ok - but thats systemd for you… (of course it could also be a completely random fluke)

Yeah, I remember a misleading doc and found this one in my scripts:

# ensure an unique machine-id
rm -f /etc/machine-id
dbus-uuidgen --ensure=/etc/machine-id
rm -f /var/lib/dbus/machine-id
dbus-uuidgen --ensure