Autoinstall: script for setting hostname based on serialnumber

Here is another script that allows to set hostname early in autoinstall deployment and based on serialnumber.

prereq: knowledge of how to build your custom iso with autoinstall.

I made a script called pre-install-sethostname.sh and it gathers data about the computers serialnumber and sets variable on it, where it later uses that and sets the hostname.

Scripts depends on that hostname is set as unassigned-hostname in the yaml file (if you want to use other, just make sure same is both in yaml-file and script)

  identity:
    hostname: unassigned-hostname

script: (which exchanges this unassigned-hostname to hostname WS-“SERIALNUMBER”)
Exchange WS to whatever you want.

#!/bin/sh
#
vSerialNumber=$(sudo dmidecode -s system-serial-number)
#
sed -i -e "s/unassigned-hostname/WS-${vSerialNumber}/" "/autoinstall.yaml"

The script will be called in the yaml file from here

  # EARLY COMMANDS
  early-commands:
    - bash /cdrom/nocloud/scripts/pre-install-sethostname.sh
2 Likes