localhost.localdomain instead of the hostname when registered in Anaconda using a Kickstart file

Posted on

I recently automated RHEL 8 installation with a Kickstart file. Everything works as expected except the registration. I always get a system named localhost.localdomain in Red Hat Subscription Management. In the network table of system facts, the hostname is always localhost.localdomain, and ipv4_address is

There is this static network configuration with a hostname configured (I tried both FQDN and a short one) in my Kickstart file:

network  --bootproto=static --device=ens192 --gateway=<gateway_ip> --ip=<device_ip> --nameserver=<dns_ip> --netmask= --noipv6 --activate
network  --hostname=myhostname

I also tried this in one network command, but the result was the same.

The rhsm configuration is as follows:

rhsm --organization="<organization_id>" --activation-key="<activation_key>"

When I manually unregister that system and register it again, its hostname is correct. When I do the same installation procedure manually, everything is fine. I’m wondering if the timing makes the difference here.

I went through the syslog and found a few interesting events:

# less /var/log/anaconda/syslog | grep 'localhost.localdomain\|myhostname'
14:26:19,528 INFO NetworkManager:<info> [1637245579.5285] policy: set-hostname: set hostname to 'localhost.localdomain' (no hostname found)
14:26:19,529 INFO systemd-hostnamed:Changed host name to 'localhost.localdomain'
14:26:37,391 WARNING org.fedoraproject.Anaconda.Modules.Network:DEBUG:anaconda.modules.network.network:Hostname is set to myhostname
14:26:54,572 INFO rhsm-service: INFO [subscription_manager.managerlib:72] Consumer created: localhost.localdomain (dc452966-de3e-4177-a970-9a1c45ba9850)
14:35:19,094 INFO systemd-hostnamed:Changed host name to 'myhostname'
14:35:19,097 WARNING org.fedoraproject.Anaconda.Modules.Network:DEBUG:anaconda.modules.network.network:Current hostname is set to myhostname
14:35:19,099 WARNING org.fedoraproject.Anaconda.Modules.Network:DEBUG:anaconda.modules.network.network:Current hostname changed to myhostname

At 14:26:19,529, system-hostnamed informed that the hostname was changed to localhost.localdomain. However, at 14:26:37,391, Anaconda’s network module reported that the correct hostname string was set. Around 17 seconds later there was information from the rhsm-service that the consumer named localhost.localdomain was created.
Finally, at 14:35:19,094, system-hostnamed reported that the hostname was changed to myhostname. At almost the same time, Anaconda.Modules.Network reported the same. I assume that this was when the system was installed.

I also searched the log for initial rhsm.service events:

# less /var/log/anaconda/syslog | grep rhsm-service
14:26:32,920 INFO rhsm-service:WARNING [rhsm.logutil:170] logging already initialized
14:26:37,925 INFO rhsm-service:DEBUG [rhsmlib.file_monitor:305] Enabling watcher: /etc/rhsm/rhsm.conf again
14:26:45,355 INFO rhsm-service:DEBUG [rhsmlib.dbus.objects.config:120] Setting new configuration values: {'server.hostname': 'subscription.rhsm.redhat.com', 'server.proxy_hostname': '', 'server.proxy_port': '-1', 'server.proxy_user': '', 'server.proxy_password': '', 'rhsm.baseurl': 'https://cdn.redhat.com'}
14:26:45,356 INFO rhsm-service:DEBUG [rhsmlib.file_monitor:294] Temporary disabled watcher: /etc/rhsm/rhsm.conf for 5 seconds

server.hostname configuration value was set at 14:26:45,355, and it was localhost.localdomain.

So the main questions are:
1. Why do these two services/modules report different hostname values?
2. Is there a mistake in my Kickstart file?

I found a workaround. With some extra commands in the %post section:

subscription-manager remove --all
subscription-manager unregister
subscription-manager clean
subscription-manager register --org="<organization_id>" --activationkey="<activation_key>"

I’m getting a system with the correct name and network values in Red Hat Subscription Management.
Initially, I used the clean command only, because RH's "subscription-manager command cheat sheet" states that it:
"Removes all local system and subscription data without affecting the server (effectively doing an unregister and remove)"

Please help me understand the whole process because I ran out of ideas on how to fix it without the workaround.