Sometimes for reasons unknown to me a "transient" name was set in hostnamectl and this causes a fight between systemd-resolved and other things trying to set the hostname, as systemd runs many things in parallel it depends which thing runs last to find which hostname you end up with. The addition here will set the hostname using hostnamectl if the command is in the path and it reports either it's static or transient name as different from desired.
Sometimes for reasons unknown to me a "transient" name was set in hostnamectl and this causes a fight between systemd-resolved and other things trying to set the hostname, as systemd runs many things in parallel it depends which thing runs last to find which hostname you end up with. The addition here will set the hostname using hostnamectl if the command is in the path and it reports either it's static or transient name as different from desired.