Sub topic 18
Repeating the install with automation
You have now built one server by hand. This chapter covers how to turn those choices into a file so the installer can repeat them without you. It assumes you are comfortable with the earlier chapters: partitioning, installer options, an admin user with sudo, SSH keys, and the baseline checklist. You also need to be able to boot a virtual machine and read a short YAML or key-value file.
Why automate
A manual install depends on memory and on careful clicking. Two servers built a month apart can differ in small ways: one has a different swap size, another still allows password logins. An answer file removes that drift. It also gives you something to review in version control, and it lets you rebuild a failed machine in minutes.
Automation does not replace the baseline you built earlier. It records that baseline. Build one server by hand first, write down what you did, and only then translate it into a file.
The three mechanisms
Each major distribution family has its own installer and its own answer-file format. All three work the same way: the installer boots, fetches a file, and answers its own questions from that file.
| Family | Installer | Answer file | Typical way to supply it |
|---|---|---|---|
| Debian | debian-installer | Preseed (`preseed.cfg`) | Kernel parameter `auto=true priority=critical url=...` |
| RHEL family (Rocky, Alma, Fedora) | Anaconda | Kickstart (`ks.cfg`) | Kernel parameter `inst.ks=...` |
| Ubuntu Server | Subiquity | Autoinstall (cloud-init `user-data`) | Kernel parameter `autoinstall ds=nocloud-net;s=...` |
Kickstart for the RHEL family
A kickstart file lists one command per line. It covers the same decisions you made by hand: language, network, user, partitioning, firewall, and packages.
# ks.cfg
text
lang en_US.UTF-8
keyboard us
timezone UTC --utc
network --bootproto=dhcp --hostname=web01
# Lock root; use a wheel-group admin with a key instead
rootpw --lock
user --name=admin --groups=wheel --iscrypted --password=REPLACE_WITH_HASH
sshkey --username=admin "ssh-ed25519 AAAA...your-public-key... admin@workstation"
# Wipe the first disk and use LVM
zerombr
clearpart --all --initlabel
autopart --type=lvm
firewall --enabled --ssh
selinux --enforcing
services --enabled=sshd,chronyd
reboot
%packages
@core
chrony
%endGenerate the password hash on your own computer with openssl passwd -6, and paste the result in place of REPLACE_WITH_HASH. Never put a plain-text password in the file.
Check the syntax before you use it. The pykickstart package provides a validator:
ksvalidator ks.cfgBoot the installer and press Tab or e at the boot menu to add inst.ks=http://192.0.2.10/ks.cfg to the kernel line. The address here is an example, so use your own web server's.
Preseed for Debian
Preseed uses lines of the form d-i owner key type value. Each line answers one installer question.
d-i debian-installer/locale string en_US.UTF-8
d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string web01
d-i netcfg/get_domain string example.com
d-i passwd/root-login boolean false
d-i passwd/user-fullname string Admin
d-i passwd/username string admin
d-i passwd/user-password-crypted password REPLACE_WITH_HASH
d-i clock-setup/utc boolean true
d-i time/zone string UTC
d-i partman-auto/method string lvm
d-i partman-auto/choose_recipe select atomic
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
tasksel tasksel/first multiselect standard, ssh-server
d-i pkgsel/update-policy select unattended-upgrades
d-i finish-install/reboot_in_progress noteAt the boot menu, add auto=true priority=critical url=http://192.0.2.10/preseed.cfg. The priority=critical setting hides every question except critical ones, so any question your file does not answer will stop the install and wait for you.
Autoinstall for Ubuntu Server
Ubuntu's installer reads a YAML file under an autoinstall: key. It delivers the file through cloud-init's NoCloud data source, which needs two files in the same directory: user-data and an empty meta-data.
#cloud-config
autoinstall:
version: 1
locale: en_US.UTF-8
keyboard:
layout: us
identity:
hostname: web01
username: admin
password: "REPLACE_WITH_HASH"
ssh:
install-server: true
authorized-keys:
- ssh-ed25519 AAAA...your-public-key... admin@workstation
allow-pw: false
storage:
layout:
name: lvm
packages:
- chrony
updates: security
late-commands:
- curtin in-target --target=/target -- timedatectl set-timezone UTCSet allow-pw: false only because you also supplied a key. The identity password hash is still needed for sudo.
Serve the directory and add the kernel parameters. In GRUB, escape the semicolon:
# On a machine that holds user-data and meta-data
python3 -m http.server 8000
# Kernel line at the installer's boot menu:
# autoinstall ds=nocloud-net\;s=http://192.0.2.10:8000/Practical rules
- Keep answer files in version control. Treat the hash and key as the only values that differ per environment.
- Keep secrets out of the repository. A password hash is not a plain-text password, but it can still be attacked offline. Prefer SSH keys, and inject hashes at build time if you must use one.
- Serve files over a network you trust. An attacker who can alter your answer file controls your server, so use HTTPS or an isolated provisioning network.
- Put differences in the file, not in memory. Hostname, disk device, and network addresses are the usual per-host changes.
- Finish with the checklist. Run the commands from the verification chapter (
ip -br addr,ss -tlnp,systemctl --failed,df -h,journalctl -p err -b) on every automated build. An unattended install can succeed and still produce the wrong system.
Common errors
- The installer stops at a question. The file is missing an answer. On Debian, run the install once with default priority and note the question's key.
- The file is not fetched. Check the URL from another machine and confirm the installer has a network address, for example by watching your web server's log.
- Autoinstall ignores the file. The kernel line must contain the word
autoinstall, and the semicolon must be escaped in GRUB. Withoutautoinstall, Subiquity shows its normal screens. - The system boots but you cannot log in. Usually the key or hash was pasted with a stray line break. Check it with
ssh-keygen -lffor keys. - BIOS and UEFI machines differ.
autopartand the Ubuntulvmlayout choose the right boot partitions for the mode, but a hand-written partition recipe may not. Test both firmware modes if you run both.
Exercise
You wrote a kickstart file that works on your test VM. On a second server, the install finishes, but you cannot log in over SSH with your key. List two things you would check in the file and one command you would run on your own computer.
Show answer
Check that the sshkey line names the correct --username (the same user created by the user line), and that the public key was pasted as one complete line with no line break. Also check that services --enabled=sshd is present and the firewall line allows SSH. On your own computer, run ssh-keygen -lf on the public key file to confirm it is valid and matches the key you meant to install, then run ssh -v admin@server to see which authentication step fails.