[SOLVED] hostname not set via CloudInit with --cicustom and Ubuntu 22.04

uncle.cripple

Member
Jul 30, 2019
16
3
8
46
I have an issue with CloudInit on Proxmox 7.2 and Ubuntu 22.04, that the hostname of the VM given in the Proxmox GUI will not be set in the VM.

As basis i use the CloudImage jammy-server-cloudimg-amd64.img of Ubuntu from https://cloud-images.ubuntu.com/jammy/current/

I have two CloudInit files, one for user and one for vendor (see below), which both get added to the template. The template gets created with the following steps:
Bash:
#!/bin/bash
qm create 800001 --name ubuntu-2204-cloud-init --numa 0 --ostype l26 --cores 2 --sockets 1 --memory 2048 -net0 virtio,bridge=vmbr100,firewall=1
qm importdisk 800001 /mnt/pve/nas02-templates/template/iso/jammy-server-cloudimg-amd64.img nas02-images --format=qcow2
qm set 800001 --scsihw virtio-scsi-pci --scsi0 nas02-images:800001/vm-800001-disk-0.qcow2
qm resize 800001 scsi0 50G
qm set 800001 --boot c --bootdisk scsi0
qm set 800001 --serial0 socket --vga serial0
qm set 800001 --ide2 nas02-images:cloudinit
qm set 800001 --agent enabled=1
qm set 800001 --cicustom "user=nas02-templates:snippets/cloudinit-user.yml,vendor=nas02-templates:snippets/cloudinit-vendor.yml"
qm template 800001

Afterwards i clone my VM in the Proxmox GUI from the template created with for example the following options:
  • VM ID: 100044
  • Name: derufin --> this should be the hostname
  • Resource Pool: test-VMs
  • Mode: Full Clone
  • Target Storage: nas02-images-ssd
  • Format: qcow2
Then i configure the following CloudInit settings in the VM:
  • DNS domain: domain.info
  • DNS servers: 172.16.100.10
  • IP Config (net0)
    • IPv4/CIDR: 172.16.100.44/22
    • Gateway (IPv4): 172.16.100.1
I do NOT touch or set User, Password and SSH public key, because this is set via cloudinit-user.yml.

When starting the VM everything get's set as expected, but the hostname of the VM is still ubuntu and not derufin!

If i add hostname: derufin to either of my two CloudInit files, the hostname get's set accordingly. But for obvious reasons i do not want to set a hostname in a template!

If i remove the user CloudInit file cloudinit-user.yml from the template, the hostname get's set correctly, but then there is no user to log in with.

On strange thing i found. When dumping the CloudInit config from the VM via qm cloudinit dump 100044 user is, that the hostname, manage_etc_hosts and fqdn is found here in the user-configuration. Why is this in user? Shouldn't that be part of network or meta?
YAML:
#cloud-config
hostname: derufin
manage_etc_hosts: true
fqdn: derufin.domain.info
chpasswd:
  expire: False
users:
  - default
package_upgrade: true

Anyway, i don't know how to set the hostname of the VM correctly. Not sure if this is a bug or if i am missing something here.

Content of cloudinit-user.yml:
YAML:
#cloud-config
disable_root: true
chpasswd:
  expire: false
groups: mygroup
users:
  # - default
  - name: myuser
    primary_group: mygroup
    lock_passwd: false
    passwd: $6$C/JR12t/ia5qRYcy$CDhsc.T5rEkvlnaofABfYzwuJ7VH.1RQWy63iRVrbSiljnPh.myDQcDGlzisZQlLXwNSxDKeJJL1wjhoAWD1d0/
    shell: /bin/bash
    ssh-authorized-keys:
      - ssh-rsa AAAAsomekeygarble my.user@domain.info
    groups:
      - mygroup
      - adm
    sudo:
      - "ALL=(ALL:ALL) ALL"

runcmd:
  - 'groupmod --gid 1000 mygroup'
  - 'usermod --comment "My User" myuser'
  - 'usermod --uid 1000 myuser'
  - 'usermod --gid 1000 myuser'

Content of cloudinit-vendor.yml:
YAML:
#cloud-config
manage_etc_hosts: true

# locale: de_DE.UTF-8
timezone: Europe/Berlin

package_update: true
package_upgrade: true
package_reboot_if_required: true
packages:
  - qemu-guest-agent
  - nfs-common
  # - postfix
  - ntp
  - lynx
  # - landscape-client
  - apt-transport-https

VM Configuration /etc/pve/qemu-server/100044.conf:
YAML:
agent: enabled=1
boot: c
bootdisk: scsi0
cicustom: user=nas02-templates:snippets/cloudinit-user.yml,vendor=nas02-templates:snippets/cloudinit-vendor.yml
cores: 2
ide2: nas02-images-ssd:100044/vm-100044-cloudinit.qcow2,media=cdrom,size=4M
ipconfig0: ip=172.16.100.44/22,gw=172.16.100.1
memory: 2048
meta: creation-qemu=6.2.0,ctime=1654253465
name: derufin
nameserver: 172.16.100.10
net0: virtio=BA:F3:9E:CC:3B:9F,bridge=vmbr100,firewall=1
numa: 0
ostype: l26
scsi0: nas02-images-ssd:100044/vm-100044-disk-0.qcow2,size=50G
scsihw: virtio-scsi-pci
searchdomain: domain.info
serial0: socket
smbios1: uuid=f2907c6c-22e8-4ed6-99f1-924a1cb666a1
sockets: 1
vga: serial0
vmgenid: 1e457e02-041e-4056-8ab7-7e63d2d1567b

Proxmox Version:
Code:
proxmox-ve: 7.2-1 (running kernel: 5.15.35-1-pve)
pve-manager: 7.2-4 (running version: 7.2-4/ca9d43cc)
pve-kernel-5.15: 7.2-3
pve-kernel-helper: 7.2-3
pve-kernel-5.13: 7.1-9
pve-kernel-5.4: 6.4-7
pve-kernel-5.3: 6.1-6
pve-kernel-5.15.35-1-pve: 5.15.35-3
pve-kernel-5.15.30-2-pve: 5.15.30-3
pve-kernel-5.13.19-6-pve: 5.13.19-15
pve-kernel-5.13.19-5-pve: 5.13.19-13
pve-kernel-5.13.19-4-pve: 5.13.19-9
pve-kernel-5.13.19-3-pve: 5.13.19-7
pve-kernel-5.13.19-2-pve: 5.13.19-4
pve-kernel-5.13.19-1-pve: 5.13.19-3
pve-kernel-5.4.143-1-pve: 5.4.143-1
pve-kernel-5.4.140-1-pve: 5.4.140-1
pve-kernel-5.3.18-3-pve: 5.3.18-3
ceph-fuse: 14.2.21-1
corosync: 3.1.5-pve2
criu: 3.15-1+pve-1
glusterfs-client: 9.2-1
ifupdown: 0.8.36+pve1
ksm-control-daemon: 1.4-1
libjs-extjs: 7.0.0-1
libknet1: 1.22-pve2
libproxmox-acme-perl: 1.4.2
libproxmox-backup-qemu0: 1.3.1-1
libpve-access-control: 7.2-1
libpve-apiclient-perl: 3.2-1
libpve-common-perl: 7.2-2
libpve-guest-common-perl: 4.1-2
libpve-http-server-perl: 4.1-2
libpve-storage-perl: 7.2-4
libqb0: 1.0.5-1
libspice-server1: 0.14.3-2.1
lvm2: 2.03.11-2.1
lxc-pve: 4.0.12-1
lxcfs: 4.0.12-pve1
novnc-pve: 1.3.0-3
proxmox-backup-client: 2.2.1-1
proxmox-backup-file-restore: 2.2.1-1
proxmox-mini-journalreader: 1.3-1
proxmox-widget-toolkit: 3.5.1
pve-cluster: 7.2-1
pve-container: 4.2-1
pve-docs: 7.2-2
pve-edk2-firmware: 3.20210831-2
pve-firewall: 4.2-5
pve-firmware: 3.4-2
pve-ha-manager: 3.3-4
pve-i18n: 2.7-2
pve-qemu-kvm: 6.2.0-8
pve-xtermjs: 4.16.0-1
qemu-server: 7.2-3
smartmontools: 7.2-pve3
spiceterm: 3.2-2
swtpm: 0.7.1~bpo11+1
vncterm: 1.7-1
zfsutils-linux: 2.1.4-pve1
 
Last edited:
When you "dump" cloudinit config it shows you what it would look like if you _didnt_ have custom setup.
The hostname is set from "meta" which you are not defining. You are going to have to find a way to provide proper "meta" file. In our environment we roughly do:
cp meta_template vmid_meta_file
use sed/etc to replace INSTANCEID and HOSTNAME with appropriate values

The resulting file is added to config meta=nas:snippets/$META:
Code:
{
"instance-id": "2000",
"local-hostname": "vm2000"
}


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
@bbgeek17 Thanks for your answer and sorry for the late reply.
Is there a way to dynamically add the Meta-Configuration to the Template, depending on the VM-ID?
Or is it possible to use a Variable in the Meta-Template to reference the hostname from the VM-configuration?

My users creating a (Dev/Test/Whatever) VM should only use the Proxmox GUI, add the hostname and IP-address and nothing more. But this seems to be impossible at the moment.
 
Turns out, there is a quite simple - albeit not obvious, at least not to me - solution to set the hostname in the above mentioned scenario, while still using the cloudinit-user.yml and cloudinit-vendor.yml files!

As mentioned in the cloud-init documentation for the datasource NoCloud you can pass the hostname (and some more) via SMBIOS Serial number. So adding ds=nocloud;h=derufin into my cloned VMs "Options -> SMBIOS settings (type1) -> Serial"-field did the trick for me.
 
As far as I understand there is no way to automatically insert hostname from VM name in a clone stage ? I am looking for a solution to take hostname from VM name automatically without additional step.
 
Bumping this to see if there is anyway to set the hostname via jinja templating features for cloud-config in proxmox?

I've queried the cloud-config files for vanila proxmox configured cloud-init in vms and in instances that I have use a --cicustom to create my own cloud-init config, and the difference is many of the `v1` or `metadata` info is missing.

this is the command for mounting my custom cloudinit files:


Bash:
qm set 9001 --cicustom "user=local:snippets/alpine-user.yml,network=local:snippets/alpine-network.yml"

JSON:
{
"v1": {
  "_beta_keys": [
   "subplatform"
  ],
  "availability-zone": null,
  "availability_zone": null,
  "cloud-name": "unknown",
  "cloud_id": "nocloud",
  "cloud_name": "unknown",
  "distro": "alpine",
  "distro_release": "Alpine Linux v3.19",
  "distro_version": "3.19.0",
  "instance-id": "1facf3598efb52159bfa245b9c6d4b2341bc7fd4",
  "instance_id": "1facf3598efb52159bfa245b9c6d4b2341bc7fd4",
  "kernel_release": "6.6.4-1-virt",
  "local-hostname": "(none)",
  "local_hostname": "(none)",
  "machine": "x86_64",
  "platform": "nocloud",
  "public_ssh_keys": [],
  "python_version": "3.11.6",
  "region": null,
  "subplatform": "config-disk (/dev/sr0)",
  "system_platform": "Linux-6.6.4-1-virt-x86_64-with",
  "variant": "alpine"
 }
 

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!