@ wrote... (3 years, 3 months ago)

Not gonna lie, getting this to work was hard, plus I'm still not super happy with the results but it's good enough. You can set a static ip in the Proxmox cloud-init disk and that's what you'll end up with on first boot.

Note: this probably also applies to Ubuntu 18.04

There is probably a way better way to get here but this is what I ended up doing.

  1. download and install latest cloud image in a vm
  2. after booting tweak the image as you see fit
  3. prepare the image for templating by unsetting hostname, deleting .bash_history, etc
  4. run cloud-init clean
  5. poweroff the vm
  6. in Proxmox convert vm to a template (this is v1)
  7. clone v1 template and boot it
  8. paste the script that's below in shell
  9. poweroff
  10. convert vm to a template (this is v2, you'll probably want to make this a full clone)
  11. clone v2 template, this vm should “just work”


You can just paste the following in your shell.

Why couldn't we do this in the first image? Not sure, but something happens on first boot of v2 that files are created, files are deleted, etc. Just do the steps twice and get on with your life.

Or if you know what's going on leave a comment below.

# nic must have "old" name, eg. eth0 and not ens18
cat << EOF > /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="eth0"

# this prevents network configuration from happening, says so right in the name
rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg

# ConfigDrive needs to come first (I think)
cat << EOF > /etc/cloud/cloud.cfg.d/99-pve.cfg
datasource_list: [ConfigDrive, NoCloud]

# this is super important, netplan files are not regenerated if they exist
rm -f /etc/netplan/00-installer-config.yaml
rm -f /etc/netplan/50-cloud-init.yaml

cloud-init clean
# reboot

Even though I just finished getting this working I've written this from memory so I may have missed something. Also you may have to repeat making a template v3 from v2. You'll know if you have a dhcp address and the files the script deleted still exist.

/etc/netplan/50-cloud-init.yaml should have your static ip after booting.

Category: tech, Tags: devops, linux, proxmox, ubuntu
Comments: 6
Bert De Meyer @ December 19, 2020 wrote... (3 years, 2 months ago)

Thanks for this, I have been looking forever to get this working. :-)

Marco @ March 25, 2021 wrote... (2 years, 11 months ago)

Great work, thank you! Would you maybe have any hints on how to prevent Cloud-Init from changing /etc/apt/sources.list upon every regeneration of the cloudinit disk drive?

Kurt @ March 25, 2021 wrote... (2 years, 11 months ago)

I'm sure there's a way but I don't know what it is. I find that cloud-init is one of those things that is great as long as it already does exactly what you want.

vinci @ September 7, 2021 wrote... (2 years, 5 months ago)

I've been struggling with running cloud-init once more (after templating a vm with packer - initially I get it working through the kernel command line and that's ok), but afterwads I had reached an impasse. Very grateful for your solution as is. I'll try to document this and spread the knowledge!

vinci @ September 8, 2021 wrote... (2 years, 5 months ago)

Just for the record: in my case it worked only by deleting subiquity-disable-cloudinit-networking.cfg and by adding the data source list in 99-pve.cfg

Kurt @ September 8, 2021 wrote... (2 years, 5 months ago)

Glad people are finding this useful. Thanks for verifying my instructions vinci.

Click here to add a comment