I do not believe there is any way to make subiquity use the hostname in the DHCP offer. However, there are a number of ways that early-commands
and late-commands
could be used to do what you want.
My suggested solution is a user-data
autoinstall file similar to this snippet. It will read the hostname in the DHCP offer from the DHCP lease file and overwrite /etc/hostname
on the installed system.
#cloud-config
autoinstall:
# NO identity section
#identity:
user-data:
users:
- name: ubuntu
passwd: REDACTED
shell: /bin/bash
lock-passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL
groups: users
late-commands:
- |
bash <<'EOF'
source <(cat /run/systemd/netif/leases/* | grep ^HOSTNAME=)
[[ -n "${HOSTNAME}" ]] && echo "${HOSTNAME}" > /target/etc/hostname
EOF
true
These are some gotchas to watch out for no matter what approach you try.
- The
autoinstall
identity
and user-data
sections do not co-exist well. My preference is to use a user-data
section and to not include an identity
section. Because the only provided way to configure the hostname is the identity
section another method must be used to configure the hostname (e.g. late-commands
).
- If there is no
identity
section then subiquity changes behavior. The generated cloud-init configuration (in /target/etc/cloud/cloud.cfg.d/99-installer.cfg
) will be different. There will be no /target/etc/hosts
content generated and the file will be left empty. There are potentially other differences.
- Conversely, if there is an
identity
section then the provided hostname
will be configured in multiple files. In /target/etc/hosts
and potentially others.
see also
notes
- I tested using Ubuntu 22.04 (
subiquity 22.04.2
).