Setting host name via cloud-init

mgiammarco

Renowned Member
Feb 18, 2010
165
10
83
Hello,
I have installed an ubuntu 18.04 vm and configured cloud-init.
Ubuntu cloud-init overwrites hostname at boot with "ubuntu18.04server"
Now I would like to configure hostname with cloud-init but I do not see hostname options in proxmox cloud-init menu.

Can you help me?
Thanks in advance,
Mario
 
Hi,

the host name is the VM name.
 
Have generated the Cloudinit config Image new again?
Button on the Clout-init tab.
 
Tried again without luck
Is "vm name" the name under "options"?
I have installed ubuntu 18.04 from iso not from img but I clearly see that cloudinit packages are installed and they overwrite hostname with ubuntu1804server so they work.
 
Solved removing /var/lib/cloud/seed/nocloud.net
But I do not understand why it has to be so complex, what happens now if I build a template?
 
I have the same issue.

I changed the vm name an reinitialized the cloud-init config but the hostname in ubuntu guest is still not set to the one in PM???
 
Yep, I followed the cloud-init instructions below with ubuntu-server 20.04LTS and the hostname is not set after cloning the cloud-init configured vm https://www.youtube.com/watch?v=Ygk7oq--mak

Apparently we're not the only ones having issues, a commenter on the video I linked has a similar story:

"Thanks for the tutorial. I am trying to do the same with ubuntu 20.04. I don't get any errors, but when I start the VM or VM cloned from the image, it makes no difference. For instance, my original VM had a fixed IP but if I ask cloud-init to use dhcp, I still get the originally fixed IP, the hostname does not change and my new user is not created. Any ideas what I might be doing wrong, or does this method not work with Ubuntu?"
 
Last edited:
There are many parts of cloud-init that are only executed on first boot. If you use a vendor provided cloud image as your base - its specifically built so that on next boot cloud-init is run as if it was first time.

If one is building their own template - there is a number of steps to be taken to clean up the VM before converting it to template.

There are many articles out there describing the process, ie:
https://learn.microsoft.com/en-us/a.../server/best-practices/vmware-ubuntu-template
Which was found via "how to make ubunutu template" search keywords.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
  • Like
Reactions: EllyMae
If somebody stumbles across this thread as i did and still has the issue, that a name you set as VM name is not being set as hostname by cloud-init: It fails for me too, as long as i set a shortname. As soon as i set a FQDN as vm name, cloud init sets the hostname perfectly fine. Don't know why it is like that, but that's the only way for me to get the correct hostname set currently.
 
I ran into this issues because my cicustom file had the hostname set. So check that file too if your having issues.

I did not need use the fqdn for the VM name to get it to work on Ubuntu.

I did notice that the cloudinit command did add the fqdn to the cloud-init config when the VM name was a fqdn.

VM name: netes-master1
Bash:
qm cloudinit dump 103 user
#cloud-config
hostname: netes-master1
manage_etc_hosts: true

VM name: netes-master1.example.org
Bash:
qm cloudinit dump 103 user
#cloud-config
hostname: netes-master1
manage_etc_hosts: true
fqdn: netes-master1.example.org
 

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!