Rerunning cloud-init

chei33

New Member
Jun 15, 2021
5
2
3
44
Hi,

I have a VM set up with cloud-init according to the instructions at https://pve.proxmox.com/wiki/Cloud-Init_Support using the Ubuntu Focal cloud image. This all worked flawlessly the first time I did it (thanks!). However, later I wanted to change the network configuration without recreating the VM. I ran

Code:
qm set 100 --ipconfig0 ...
qm set 100 --net0 ...

with the new configuration. The first to update cloud-init, and the second to update kvm. However, when the VM boots, the netplan configuration file doesn't get updated, and as far as I can tell, cloud-init isn't "fully" run. So the VM was still trying to use the old config internally. What seemed to work was to run cloud-init clean and cloud-init init, then reboot (twice?), and this caused the new cloud-init config to "take".

The documentation doesn't mention whether it's supposed to be possible to rerun cloud-init when the config changes; I guessed that it's supposed to just work, and I can't find other people running into this problem! My VM config is

Code:
root@ainosticssrv02:~# qm config 100
agent: 1
bios: ovmf
boot: c
bootdisk: scsi0
cipassword: **********
cores: 16
efidisk0: local-lvm:vm-100-disk-1,size=4M
hostpci0: 81:00.0,x-vga=on
ide2: local-lvm:vm-100-cloudinit,media=cdrom
ipconfig0: ip=192.168.140.100/24,gw=192.168.140.1
memory: 131072
name: sandbox
net0: virtio=46:07:A1:74:69:EC,bridge=vmbr1
numa: 0
onboot: 1
scsi0: local-lvm:vm-100-disk-0,size=53452M
scsihw: virtio-scsi-pci
serial0: socket
smbios1: uuid=e3b0a5a4-a1a3-44fc-8766-2e250bdc4a4a
sockets: 1
sshkeys: <redacted>
vga: qxl
vmgenid: b73354d9-cb3f-4eb5-a8ab-35bff966644b

Could the use of ovmf (needed for GPU PCI passthrough) be responsible (I changed this after originally creating the VM)?

I realised later that the gateway I was setting was wrong - could it be refusing to apply the new networking because the config was wrong? There didn't seem to be anything useful in the logs.
 
  • Like
Reactions: seyed514
Network config should be applied once per instance. Did you boot it once before with the config being exactly that?
The 'instance-id' is basically the hash of the user config and the network config concatenated. cloud-init checks the current instance-id against all previously known ones to see if it has to rerun the different systems and modules, not just the previous instance-id, which leads to strange behavior sometimes.

In this case the only solution currently is to run `cloud-init clean` and then reboot.
 
Hi mira,

Thanks - that is useful information to know. It's possible that I booted it once with this config, but with some other problem which caused it to fail to boot, but the config was still registered by cloud-init but not stored in netplan, and so never "took".

Is there a way to force it to re-apply the cloud-init config, e.g. by passing a kernel parameter?

There is this post I found, https://www.burgundywall.com/post/using-cloud-init-to-set-static-ips-in-ubuntu-20-04, which suggests that the whole process with Ubuntu 20.04 and cloud-init with Proxmox is a bit messy. He's trying to something a bit more convoluted than me, I think, involving booting the image, setting it up, and then templating it, but it might be useful for other people who run across this thread, so I reference it here anyway.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!