[SOLVED] cloud-init configuration on a template then clone fails

Aved590

New Member
Sep 21, 2024
2
0
1
Virginia
Hi all.

I have been struggling a couple days trying to get my cloud-init working on a clone from a template. I'm running Proxmox 8.2.4 on a 3 node cluster. I'm only working from one node

I'm automating this process through qm commands . Build the template from Ubuntu 22.04 cloud image, set the cloud-init parameter, turn VM into a template, then clone it.

If I strictly use qm commands to set cloud-init parameters, it seems to work fine. But either the parameters are limited or I'm not using them all due to lack of knowledge.

Ultimately, I would like to use a cloud.cfg file. But every time I try to use cloud.cfg, either stand alone (no qm ci commands) or a combination, the clone builds but no ip is assigned or I can't get into the host using the defined user "srvadm" or "ubuntu".

If I remove the two lines:
qm set ${VID} --cicustom "user=local:snippets/cloud.cfg"
qm cloudinit update ${VID}

then everything seems to wor but

Can I use both cloud.cfg and qm --ci commands? Any ideas or does anyone have sample scripts that do work?

Another interesting observation. When I try to use the cloud.cfg, the login is
ubuntu login:
But when I don't use cloud.cfg, then my login is:
myclone login:

Here are the commands I was trying to use when logged into the proxmox host.


VID=9000
VID_CLONE=150
VM_NAME=myclone

qm create ${VID} --memory 1024 --core 2 --name ubuntu-cloud --net0 virtio,bridge=vmbr0
qm disk import ${VID} /tmp/jammy-server-cloudimg-amd64.img local -format qcow2
qm set ${VID} --scsihw virtio-scsi-pci --scsi0 local:${VID}/vm-${VID}-disk-0.qcow2,size=8,discard=on,ssd=1
qm resize ${VID} scsi0 4G
qm set ${VID} --scsihw virtio-scsi-pci --ide2 local:cloudinit

qm set ${VID} --ciuser srvadm
qm set ${VID} --cipassword $(openssl passwd -6 adminpass)
qm set ${VID} --ipconfig0 ip=dhcp
qm set ${VID} --sshkeys ~/.ssh/id_ed25519.pub

cat << EOF > /var/lib/vz/snippets/cloud.cfg
#cloud-config
runcmd:
- date > /etc/birth_certificate

EOF


qm set ${VID} --cicustom "user=local:snippets/cloud.cfg"
qm cloudinit update ${VID}
qm set ${VID} --boot c --bootdisk scsi0
qm set ${VID} --serial0 socket --vga serial0
qm set ${VID} --agent enabled=1
qm template ${VID}
qm clone ${VID} ${VID_CLONE} --name ${VM_NAME} --full
 
I dug deep to monitor the cloudinit qcow2 file using the "strings" command. (eg. strings /var/lib/vz/images/${VID}/vm-${VID}-cloudinit.qcow2) and watched after each step. Using qm ci commands (eg qm set ${VID} --ciuser srvadm) and with the custom cloud.cfg file.

It seems that whatever is set with qm ci commands will get overwritten. I wasn't able (yet) to get the network part working in cloud.cfg but that can be set by qm set ${VID} --ipconfig0 ip=dhcp. I don't try to configure network in the cloud.cfg file. All seems to work well then.

Bottom line, if you want to do more with cloud.cfg, then use the customer, avoid qm ci commands.
 
Using "qm ci" commands creates a cloud-init file that is supplied to the VM via ISO/cdrom. The file is generated by PVE and allows for minimal configuration that is enough to bootstrap the VM.
When you use cicustom you will supply the cloud-init file that you wrote. This file can be arbitrarily complex.

PVE cannot merge the two files which could potentially contain conflicting information. When you use cicustom - the internal settings get ignored.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 

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!