Chapter 27. Automation and Configuration Management
Automation is how a system administrator stops being the bottleneck between
a decision and its execution. A shell script that runs correctly at 3 a.m.
with nobody watching, a /etc tree whose every change is recorded and
reversible, a control node that pushes a baseline to a fleet in one command,
a network that installs a new machine without a keyboard attached, and a
scheduler that runs the same job whether it succeeds or fails - these are
five faces of the same discipline, and this chapter treats them in that
order. Each stage builds on the previous one: the scripting section
establishes the reliability habits (quoting, exit status, atomic
replacement, idempotence) that the configuration-management and
provisioning sections then apply at larger scale, and the closing section
returns to the smallest unit - a job that runs repeatedly - now with its
scheduling, locking, reporting, and testing treated as separate concerns.
The examples run on two small Debian 13 systems:
| Role | Host | eth1 (isolated network) |
Responsibility |
|---|---|---|---|
| Control node, configuration code, provisioning server | auto1 | 192.168.227.10/24 | Ansible control, etckeeper, DHCP/TFTP/HTTP provisioning, systemd timer |
| Managed node, provisioning client | auto2 | 192.168.227.20/24 | Ansible managed host, DHCP/TFTP/HTTP client for boot tests |
Both machines keep a second interface (eth0) on a management network that
carries administrative SSH and package downloads; every exercise in this
chapter runs over the isolated 192.168.227.0/24 link so that no procedure
can cost the administrator access. The addresses are examples - replace
them with your own. One machine is enough for Sections 27.1, 27.2, 27.4,
and 27.6; the Ansible walkthrough in Section 27.3 needs a second host to
manage, and the PXE material in Section 27.5 uses the second host as a
stand-in for a machine that boots from the network. Building that second
host as a libvirt guest is covered in Chapter 24;
attaching it to an isolated network is covered in Section 24.3.3.
Figure 27.1. The two practice hosts. The management network keeps administrative SSH out of every exercise; the isolated 192.168.227.0/24 network carries Ansible SSH, DHCP, TFTP, and HTTP traffic between auto1 and auto2.
The package versions used throughout are the Debian 13 (trixie) ones:
$ dpkg-query -W -f='${Package} ${Version}\n' shellcheck ansible-core etckeeper cloud-init isc-dhcp-server
ansible-core 2.19.11-0+deb13u1
cloud-init 25.1.4-1+deb13u1
etckeeper 1.18.22-2
isc-dhcp-server 4.4.3-P1-8
shellcheck 0.10.0-1
Commands entered in john's ordinary shell begin with $; commands entered
in a root shell begin with #; the prompt marker itself is not typed. A
single elevated command from john's shell is written $ sudo command. On
a stock installation sudo asks for john's password the first time in a
session and does not echo it; john's administrative access is whatever
Chapter 5 established for your systems. When
a procedure says "in the root shell", enter sudo -i from john's shell and
leave it with exit. Example files that belong to john live under
~/debian-handbook/automation, created the first time they are needed;
the tilde expands to /home/john only in john's own shell, so a
privileged command that must act on john's workspace spells the path out.
Each console block shows one command (or one explicitly bounded sequence)
followed by its own output. The practice guests were prepared with the
packages already installed, so the apt install captures below show apt
confirming the installed version instead of downloading it. apt also prints
a reminder on standard error that its command line is meant for people
rather than scripts; the blocks show the standard output, and
Chapter 6 covers the scripted alternative.
Chapter 3 covered the shell operators used here
(|, >, >>, 2>, &&) and exit status basics;
Chapter 8 covered systemd units and the journal;
Chapter 10 covered timers and cron mechanics;
Chapter 20 covered SSH keys and host-key verification;
Chapter 22 covered DHCP service design with Kea. This
chapter builds on all of them without repeating their mechanics, except
where automation changes how the tool is used.