Cloud-init on Centos8 ( set-hostname not working )

him

New Member
Jul 26, 2021
6
0
1
31
I have a problem with my Centos8 template
I created a template based on the cloud image provided by centos (official)
as a provider we give as hostname the same name as the vm but in this case (centos8 temp) the hostname of the vms deployed via centos 8 template keeps the previous hostname Localhost.
on other templates like debian or ubuntu the hostname is defined normally
I have tried several cloud image centos 8 & 9 and I have the same problem

pve version 6.4-14
cloud-init version 23
 
a bit more information would be helpful:
I created a template based on the cloud image provided by centos (official)
does this mean its a non-modified cloud image or have you customized it?
as a provider we give as hostname the same name as the vm
Do you use built-in PVE cloud-init functionality or do you utilize custom cloud-init?
If former provide a "qm config [vmid]" if latter, add your custom cloud-init file.

There is also this thread https://forum.proxmox.com/threads/setting-host-name-via-cloud-init.45525 although you appear to have opposite problem OS wise.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
does this mean its a non-modified cloud image or have you customized it?
I have tested both solutions:
-deploy a ready-made cloud image
-creat my own vm template on clean install
Utilisez-vous la fonctionnalité cloud-init PVE intégrée ou utilisez-vous cloud-init personnalisé ?
Si le premier fournit un "qm config [vmid]", si ce dernier, ajoutez votre fichier cloud-init personnalisé.
I don't understand the meaning of your question but I know that cloud-init was integrated in the pve since the beginning we use whmcs modul to fill the cloud init directory
 
Last edited:
update

when I specify the DNS domain by putting ex: hostname
the hostname is defined and the etc/hostname is overwritten and contains the string we defined ex : (hostname.hostname)
 

Attachments

  • dns domaine.PNG
    dns domaine.PNG
    5.3 KB · Views: 19
I don't understand the meaning of your question but I know that cloud-init was integrated in the pve since the beginning we use whmcs modul to fill the cloud init directory
Proxmox implements a reduced set of Cloud-Init internally: https://pve.proxmox.com/pve-docs/qm.1.html#:~:text=Cloud-Init specific Options

You also have an option to use "cicustom" where you can supply a full blown cloud-init file of any supported format.
I dont know what whmcs does, it could be a conditional mixture of both.

I ran a quick test for you using "CentOS-8-GenericCloud-8.4.2105-20210603.0.x86_64.qcow2".

Using integrated cloudinit:

Name set to "vm3000" results in hostname not set properly. You can examine /etc/hosts and notice that vm3000 is there, but not in /etc/hostname
Code:
qm config 3000
cipassword: **********
ciuser: centos
ipconfig0: ip=dhcp
name: vm3000
scsi0: bb-nvme:vm-3000-disk-0,size=10G
scsi1: bb-nvme:vm-3000-cloudinit,media=cdrom

more /etc/hostname
127.0.0.1 localhost vm3000

Setting the name to FQDN results in a more expected config:
Code:
qm config 3000
cipassword: **********
ciuser: centos
ipconfig0: ip=dhcp
name: vm3000.blockbridge.com
scsi0: bb-nvme:vm-3000-disk-0,size=10G
scsi1: bb-nvme:vm-3000-cloudinit,media=cdrom

more /etc/hostname
127.0.0.1 vm3000.blockbridge.com vm3000


However, when using cicustom:
Code:
cicustom: meta=nfs:snippets/cirros.meta.3000,user=nfs:snippets/centos.user

There is no need for FQDN in hostname.

Code:
root@vm3000 centos]# mkdir /mnt/1
[root@vm3000 centos]# mount /dev/sr0 /mnt/1
mount: /mnt/1: WARNING: device write-protected, mounted read-only.
[root@vm3000 centos]# cd /mnt/1
[root@vm3000 1]# ls -al
total 5
drwxr-xr-x. 2 root root 2048 May 15 09:49 .
drwxr-xr-x. 3 root root   15 May 15 09:49 ..
-rw-r--r--. 1 root root   54 May 15 09:49 meta-data
-rw-r--r--. 1 root root  111 May 15 09:49 network-config
-rw-r--r--. 1 root root 1728 May 15 09:49 user-data
-rw-r--r--. 1 root root    0 May 15 09:49 vendor-data
[root@vm3000 1]# more meta-data
{
"instance-id": "3000",
"local-hostname": "vm3000"
}

root@pve7demo1:~# qm config 3000
cicustom: meta=nfs:snippets/cirros.meta.3000,user=nfs:snippets/centos.user
name: vm3000
scsi0: bb-nvme:vm-3000-disk-0,size=10G
scsi1: bb-nvme:vm-3000-cloudinit,media=cdrom

Notice that my custom userdata contained wrong hostname:
Code:
more user-data
#cloud-config

chpasswd:
    expire: false
hostname: vm2000
manage_etc_hosts: true

Looking at cloudinit log you can see where hostname is being changed from vm2000, to 3000 (similar messages are present for localhost in non-custom case):
Code:
grep 2000 /var/log/cloud-init*
/var/log/cloud-init.log:2023-05-15 13:49:21,939 - cc_set_hostname.py[DEBUG]: Setting the hostname to vm3000 (vm2000)
/var/log/cloud-init.log:2023-05-15 13:49:21,951 - cc_update_hostname.py[DEBUG]: Updating hostname to vm3000 (vm2000)

At high level the conclusion I make - modern cloud images prefer hostname set in metadata, which is consistent with most major cloud providers using metadata servers, rather than ISO based cloud-init.


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!