Cloud-init VM with dhcp IP uses wrong hostname

jamieInCLT

New Member
Jan 12, 2024
6
0
1
Hi folks- I'm new to Proxmox and I've run into a snag. I've got a script (below) to create a cloud-init template of Ubuntu Server (22.04 LTS), based on TechnoTim's video & blog.

It creates the image, marks it as a template, and I even got it to resize the disk.

The problem starts after I clone the template. When it starts up and tries to get an IP address from the DHCP server the hostname isn't what's sent to and registered in the DHCP server, but rather, it's just "ubuntu", and, if I make multiple clones, they're all "ubuntu". The hostname inside the VM is correct.

I've tried rebooting the newly-cloned vm, power-cycling it, renewing the DHCP, and resetting the hostname via hostnamectl, but each time it's still ubuntu. Is this a known issue? Anything else I can try, even if they're just manual steps?

Thanks,

-jamie

Here's the script, with a fake user/password, in case it helps anyone else

Code:
#!/bin/bash

[ -f "jammy-server-cloudimg-amd64.img" ] || \
   curl -LO --silent https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img

qm create 9000 --memory 4096 --core 2 --name ubuntu-cloud-jammy --net0 virtio,bridge=vmbr0,tag=100
qm importdisk 9000 jammy-server-cloudimg-amd64.img local-zfs
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-zfs:vm-9000-disk-0
qm set 9000 --ide2 local-zfs:cloudinit
qm set 9000 --boot c --bootdisk scsi0
qm set 9000 --serial0 socket --vga serial0
qm set 9000 --cipassword="cloudpass" --ciuser=clouduser
qm set 9000 --ipconfig0 ip=dhcp
qm set 9000 --sshkey pub-key
qm resize 9000 scsi0 +10G
qm template 9000

qm clone 9000 111 --name wario --full
 
Did you ever figure this out? I'm having the same issue currently. I think I can just reboot the VM after creation to re-register the new hostname. It's worked so far, but time will tell if that will consistently work.
 
Last edited:
That's pretty much what I resorted to, and have all of it in a GitHub repo forked from TechnoTim's repo.

I also added the QEMU guest agent to them so I can poll to wait for the clone to really finish coming up
 
The standard cloud image provided by major OS distros is built with the expectation that there is a Metadata service present, like the one in Openstack and AWS. PVE does not have such service.

You can provide the metadata information via a custom CI file:
Code:
{
"instance-id": "INSTANCEID",
"local-hostname": "HOSTNAME"
}

It would need to be modified for each VM and supplied via: qm set $VMID -cicustom "meta=$SNIPS/$META

Cheers


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