How to retrieve instance hostname from ucd

I’ve read whatever documentation and --help output I can get from ucd and ucd-data-fetch

I know that ucd generates /var/lib/cloud/aws-user-data when the systemd oneshot runs.

What I want to understand is whether ucd also fetches the instance hostname from metadata → the same output that you’d get from curl --silent on an EC2.

The Ask

When ucd runs at boot, does it save and/or output that hostname somewhere?

The reason I ask is because putting curl --silent > /opt/hostname.txt into a systemd oneshot appears to take about 5 seconds to run, and ucd is significantly snappier.

See below: # systemd-analyze  blame
5.314s set-hostname-metadata.service
1.248s ucd.service


Even those 5 seconds make a difference in our use-case.

Any help or info would be much appreciated!

The current implementation only picks up SSH keys from the user metadata APIs. It should grab the hostname if it’s defined in the standalone cloud-config, but not from e.g. .../meta-data/hostname. Enabling setting a hostname based on the user metadata API would be a good feature request here: Issues · clearlinux/micro-config-drive · GitHub

Thank you for the quick and helpful reply. :slight_smile:

As suggested, I’ve created the feature request.