As workaround, use a early command to set hostname from DNS.
1. Extract first default interface from "ip route" 2. Get ipv4 of that interface 3. Extract "host $ip" short hostname 4. Write it to /etc/hostname
Which gives
early-commands: # Get hostname from DNS - host $(ip a show dev $(ip route | awk '/default/ {print $5; exit; }') | awk '/inet / {s=$2; sub(/\/.*/,"",s); print s}') | awk '{ s=$NF; sub(/\..*/,"",s); print s }' > /etc/hostname
As workaround, use a early command to set hostname from DNS.
1. Extract first default interface from "ip route"
2. Get ipv4 of that interface
3. Extract "host $ip" short hostname
4. Write it to /etc/hostname
Which gives
early-commands:
# Get hostname from DNS
- host $(ip a show dev $(ip route | awk '/default/ {print $5; exit; }') | awk '/inet / {s=$2; sub(/\/.*/,"",s); print s}') | awk '{ s=$NF; sub(/\..*/,"",s); print s }' > /etc/hostname