cloud-init non FQDN hostname not working as expected on AlmaLinux
Bug report
The configuration of non-Fully Qualified Domain Name (FQDN) hostnames seems to be encountering issues on AlmaLinux and other distributions based on RHEL8, such as Rocky Linux and CentOS 8.
When setting up a hostname like almalinux.lan, cloud-init successfully configures the system hostname. However, when using a non-FQDN hostname like almalinux, cloud-init fails to configure it properly, leaving the hostname as localhost.
Steps to reproduce the problem
- AlmaLinux image created with Packer utility on Proxmox, latest version of cloud-init installed from repo with command
dnf install cloud-init -y - In Proxmox right click on created image, selected Clone image.
- In new window setup
Nameand click Clone - Proxmox created Cloud-init disk with name
cidatawith following content of user-data - Started Linux
What I understand is that user-data is different.
In case of almalinux.lan, fqdn key in user-data was created by Proxmox. Hostname was correctly set up .
In case of almalinux, no fqdn key in user-data was created by Proxmox. Hostname was not correctly set up .
user-data of almalinux.lan
#cloud-config
hostname: almalinux
manage_etc_hosts: true
fqdn: almalinux.lan
chpasswd:
expire: False
users:
- default
package_upgrade: true
user-data of almalinux
#cloud-config
hostname: almalinux
manage_etc_hosts: true
chpasswd:
expire: False
users:
- default
package_upgrade: true
Later I checked image created for Ubuntu with non FQDN hostname.
In case of ubuntu, no fqdn key in user-data was created by Proxmox. But hostname was correctly set up.
user-data of ubuntu
#cloud-config
hostname: ubuntu
manage_etc_hosts: true
chpasswd:
expire: False
users:
- default
package_upgrade: true
Environment details
- Cloud-init version:
/usr/bin/cloud-init 23.1.1-10.el8.alma.1 - Operating System Distribution:
NAME="AlmaLinux" VERSION="8.9 (Midnight Oncilla)" - Cloud provider, platform or installer type: Proxmox 7.3-4
cloud-init logs
Links
Similar topic on Proxmox forum
Thanks, @kovalroma, for making cloud-init better.
The difference between Ubuntu and Almalinux is that Almalinux sets prefer_fqdn to True, this value determines whether fqdn is preferred over hostname when prefer_fqdn_over_hostname is not given in the user-data.
cc_set_hostname calls util.get_hostname_fqdn, and this function computes the fqdn using cloud metadata information (in your case QEMU), using cloud.get_hostname, but ignoring that fqdn is localhost (default fallback or explicitly set as that in the metadata).
Adding up the previous paragraphs results in cloud-init setting up the hostname as localhost.
As a workaround, you could set prefer_fqdn_over_hostname to false in the user-data. One possible way to solve this is to prefer hostname over fqdn if fqdn is the default localhost, returning that info from util.get_hostname_fqdn and extending HostnameFqdnInfo.
In order to verify what's the qemu metadata, could you please collect and attach the full cloud-init logs, making sure that any sensitive information is redacted?
Thanks.
Hello @aciba90, and thank you for your detailed explanation.
Attached 2 logs.
cloud-init_hostname_alma-tst.tar.gz -> Log generated on VMs named alma-tst
cloud-init_hostname_alma-tst.lan.tar.gz -> Log generated on VMs named alma-tst.lan
cloud-init_hostname_alma-tst.lan.tar.gz
cloud-init_hostname_alma-tst.tar.gz