After running cloud-init with a user-data containing:
I find that every time I run sudo (for any command), it prints a warning:
$ sudo true
sudo: unable to resolve host pi5: Name or service not known
/etc/hostname is set correctly:
but /etc/hosts has the default value:
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 raspberrypi
Manually running sudo raspi-config nonint do_hostname pi5 sets /etc/hosts correctly, fixing the issue.