I know that it is possible to restrict systemd units to a specific host by using the
ConditionHost condition in the unit file. This
ConditionHost is tested against the result of calling hostname.
What I have not been able to find (but I'm hoping this is possible) is a way to do the same based on a DNS alias. So I'm hoping for a way to start systemd units on hosts where the DNS alias specified in the unit file resolves to the current host.
Background: At the moment we have a series of applications/services, started as systemd services, and grouped into systemd targets. Each service unit file contains a ConditionHost specifying on which host this service should run. The unit files are distributed via RPMs, and all unit files are installed on all hosts. One can now start the same systemd target on all these hosts and systemd will take care of starting the correct services on the correct hosts, based on the hostname. The services are typically accessed by clients using a DNS alias, and not using the hostname directly.
If one of the above hosts breaks, one could easily use a spare with the same configuration, and update the DNS alias accordingly. The inconvenience is, however, that the systemd unit files now also have to be updated to reflect the ConditionHost specification for the affected services.
The idea was that if systemd would be able to use the DNS alias instead of the hostname, it would be enough to 1) update the DNS alias, and 2) restart the systemd target on the replacement machine.