I improved the first workaround
early-commands: # Get hostname from DNS - host $(/usr/sbin/ip a show dev $(/usr/sbin/ip route show default | awk 'sub(/.*dev /,"",$0) {print $1; exit;}') | awk '/inet / {sub(/\/.*/,"",$2); print $2}') | awk 'sub(/\..*/,"",$NF) { print $NF }' > /etc/hostname - hostname $(cat /etc/hostname)
Another one is to use json output of ip binary
early-commands: # Get hostname from DNS - apt update && apt install -y jq - host $(/usr/sbin/ip -4 -j a show $(/usr/sbin/ip -j route show match default | jq -re '.[0].dev') | jq -re '.[0].addr_info[0].local') | awk 'sub(/\..*/,"",$NF) { print $NF }' > /etc/hostname - hostname $(cat /etc/hostname)
I improved the first workaround
early-commands:
# Get hostname from DNS
- host $(/usr/sbin/ip a show dev $(/usr/sbin/ip route show default | awk 'sub(/.*dev /,"",$0) {print $1; exit;}') | awk '/inet / {sub(/\/.*/,"",$2); print $2}') | awk 'sub(/\..*/,"",$NF) { print $NF }' > /etc/hostname
- hostname $(cat /etc/hostname)
Another one is to use json output of ip binary
early-commands: info[0] .local' ) | awk 'sub(/\..*/,"",$NF) { print $NF }' > /etc/hostname
# Get hostname from DNS
- apt update && apt install -y jq
- host $(/usr/sbin/ip -4 -j a show $(/usr/sbin/ip -j route show match default | jq -re '.[0].dev') | jq -re '.[0].addr_
- hostname $(cat /etc/hostname)