SSM Fleet Manager shows `localhost` instead of actual hostname in "Computer Name" column

0

I have a number of EC2 and on-premises managed instances (Raspberry Pi with Ubuntu 23.10). SSM Agent is pre-installed on the EC2 hosts and installed according to the docs on the on-premises instances, and Advanced Instances is enabled in SSM. Each host has a hostname defined according to the steps documented here. Running hostname on the host returns the correct hostname, and the hostname survives a reboot, so cloud-init is also configured correctly with preserve_hostname: true specified in /etc/cloud/cloud.cfg. Example from one of the EC2 hosts:

ubuntu@dev-backend:~$ hostname
dev-backend
ubuntu@dev-backend:~$ cat /etc/hosts
127.0.0.1 localhost dev-backend

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

When I enable the "Computer Name" column in Fleet Manager, all hostnames (except one) appear as "localhost": Enter image description here

Why doesn't SSM Agent correctly report the hostname to Fleet Manager?

strophy
gefragt vor einem Monat182 Aufrufe
2 Antworten
0
Akzeptierte Antwort

I was able to resolve this issue with help from ChatGPT. The issue was the way I was using Ansible to template the hostname as a second entry for the loopback interface, so even though the correct hostname was specified in both /etc/hosts and /etc/hostname, hostname -f (used internally by SSM Agent) was still returning localhost as the first matching entry. The solution was to put the hostname on the entry for 127.0.1.1 instead, which causes hostname -f to return the correct output. This works because IETF defines the loopback address as 127.0.0.0/8. Working /etc/hosts file:

127.0.0.1 localhost
127.0.1.1 dev-backend

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
strophy
beantwortet vor einem Monat
0

A few more interesting differences in the /etc/hosts files on these nodes: The single on-premises host that is reporting the hostname correctly:

pi@nucleus-v3-7:~$ cat /etc/hosts
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#
127.0.1.1 nucleus-v3-7 pi
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

The other on-premises host that reports localhost:

pi@pi-1:~$ cat /etc/hosts
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#
127.0.1.1 pi pi
127.0.0.1 localhost pi-1

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

And an EC2 host:

ubuntu@dev-backend:~$ cat /etc/hosts
127.0.0.1 localhost dev-backend

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
strophy
beantwortet vor einem Monat

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen