ubuntu 26 cloud template hostname on first start

Запись создана 10 сентября, 2026

Found a nasty bug in creating a VM from cloud template. On a first bot VM created from template sends to dhcp server an argument of hostname the templates name

for exmaple you clone a template called ‘ubuntu-26’ as ‘stage-server’, on a boot it starts a network before applying a cloud-init and hostname from it
So in DHCP you see a VM with name ubuntu-26 and thats a big problem when you use ddns to set a dns record in your network

After reboot it works as it should, but i don’t want to restart every VM on creating, so here workaround for template

cat >/etc/systemd/system/netplan-apply-after-cloud-init.service <<'EOF'
[Unit]
Description=Reapply netplan after cloud-init hostname setup
After=cloud-init.target
Wants=cloud-init.target
ConditionFirstBoot=yes
 
[Service]
Type=oneshot
ExecStart=/usr/sbin/netplan apply
RemainAfterExit=yes
 
[Install]
WantedBy=default.target
EOF
systemctl daemon-reload
systemctl disable netplan-apply-after-cloud-init.service
systemctl enable netplan-apply-after-cloud-init.service
 
  rm -f /etc/hostname
  cloud-init clean --logs --machine-id
  history -c 
  rm -rf .bash_history 
  shutdown -h now

now convert it back to template

sudo qm template 9026

» Запись из раздела Linux, Proxmox VE | Комментировать

Комментарии





Ответить