cloudinit: pass through hostname via fqdn field

If no FQDN is provided, we simply set it to the current hostname. This
ensures that the hostname *really* gets set, since we encountered an
issue on Fedora and CentOS based systems where no hostname got set at
all.

When there's no FQDN set in the cloudinit config, this leads to the
following entry:

    127.0.1.1 <hostname> <hostname>

Which doesn't seem to cause any issues.

Tested on:
 - Ubuntu 23.04
 - CentOS 8
 - Fedora 38
 - Debian 11
 - SUSE 15.4

Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
This commit is contained in:
Leo Nunner 2023-05-23 09:14:19 +02:00 committed by Thomas Lamprecht
parent 606d9d76b2
commit 3e546c5ada

View File

@ -87,6 +87,8 @@ sub get_hostname_fqdn {
$hostname =~ s/\..*$//;
} elsif (my $search = $conf->{searchdomain}) {
$fqdn = "$hostname.$search";
} else {
$fqdn = $hostname;
}
return ($hostname, $fqdn);
}
@ -120,7 +122,7 @@ sub cloudinit_userdata {
$content .= "hostname: $hostname\n";
$content .= "manage_etc_hosts: true\n";
$content .= "fqdn: $fqdn\n" if defined($fqdn);
$content .= "fqdn: $fqdn\n";
my $username = $conf->{ciuser};
my $password = $conf->{cipassword};