Unattended Upgrades on Linux Servers¶
Every major distro has a way to install updates without a human — but the tools, defaults and safety features differ a lot. This guide covers each family separately, then the cross-distro concerns: reboots, service restarts, livepatching, and orchestrating a fleet.
Contents¶
- Principles that apply to every distro
- Debian and Ubuntu: unattended-upgrades
- Fedora: dnf5 automatic
- RHEL, AlmaLinux, Rocky, Oracle Linux, CentOS Stream: dnf-automatic
- Amazon Linux 2023
- SUSE Linux Enterprise and openSUSE
- Arch Linux
- Alpine Linux
- Legacy: yum-cron (RHEL/CentOS 7)
- Restarting services after updates
- Detecting and scheduling reboots
- Kernel livepatching
- Fleet orchestration
- Quick reference
Principles that apply to every distro¶
- Security-only vs. everything. Security-only is the conservative default for production. Full updates are fine for stateless hosts that are rebuilt often.
- Updates are only half of it. Updated libraries don't take effect until processes restart; a new kernel doesn't take effect until reboot. Plan for both.
- Stagger. Never patch every replica of a service at the same moment. Use randomized delays, rings, or orchestration.
- Pin what must not move. Databases, kernels with out-of-tree modules (NVIDIA, ZFS on some distros, DKMS), and anything with a vendor support matrix.
- Snapshot when you can. Btrfs/Snapper, LVM thin snapshots, ZFS, or a hypervisor snapshot before the job runs makes a bad update a 2-minute rollback.
- Notify. Mail, a webhook, or at minimum logs shipped to your observability stack. Silent failures are how a server ends up 400 days unpatched.
- Containers aren't patched this way. Container images are patched by rebuilding them; unattended upgrades only cover the host.
Debian and Ubuntu: unattended-upgrades¶
Covers Debian 11/12/13 and Ubuntu 20.04/22.04/24.04/26.04 (and derivatives like Raspberry Pi OS, Proxmox VE hosts — with caveats below).
Install and enable¶
Ubuntu Server ships it installed and enabled for the -security pocket. On Debian, it may or may not be installed depending on installer choices.
sudo apt update
sudo apt install unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades # answers "Yes" -> writes 20auto-upgrades
The two config files¶
/etc/apt/apt.conf.d/20auto-upgrades — whether it runs:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Download-Upgradeable-Packages "1";
Values are in days ("1" = daily, "0" = disabled).
/etc/apt/apt.conf.d/50unattended-upgrades — what and how. Don't edit the packaged file if you can help it; drop overrides in a higher-numbered file such as /etc/apt/apt.conf.d/52unattended-upgrades-local so package upgrades don't produce conffile prompts.
Debian origins¶
Unattended-Upgrade::Origins-Pattern {
"origin=Debian,codename=${distro_codename},label=Debian-Security";
"origin=Debian,codename=${distro_codename}-security,label=Debian-Security";
// Uncomment for point-release updates too:
// "origin=Debian,codename=${distro_codename},label=Debian";
// "origin=Debian,codename=${distro_codename}-updates";
};
Ubuntu origins¶
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESMApps:${distro_codename}-apps-security";
"${distro_id}ESM:${distro_codename}-infra-security";
// "${distro_id}:${distro_codename}-updates";
};
The ESM lines only do anything if the host is attached to Ubuntu Pro (pro attach <token>; free for up to 5 personal machines).
Third-party repositories¶
Find the origin/label of a repo with:
apt-cache policy | grep -E 'o=|origin'
# e.g. release o=Docker,a=noble,n=noble,l=Docker CE,c=stable
then add, for example:
Unattended-Upgrade::Origins-Pattern {
"origin=Docker,label=Docker CE";
"origin=Grafana Labs";
};
Think twice before auto-upgrading Docker itself — it restarts the daemon and every container with it (unless live-restore is set in daemon.json).
Useful options¶
// Never touch these (regex since unattended-upgrades 1.x)
Unattended-Upgrade::Package-Blacklist {
"linux-image-.*"; // if you manage kernels yourself
"postgresql-.*";
"mariadb-server.*";
"nvidia-.*";
};
// Only upgrade packages with no new dependencies? (default false)
// Unattended-Upgrade::Allow-Downgrades "false";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
// Split into small steps so a shutdown mid-run doesn't leave a mess
Unattended-Upgrade::MinimalSteps "true";
// Reboots
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-WithUsers "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
// Mail (needs a working MTA / mailx: e.g. msmtp-mta or postfix)
Unattended-Upgrade::Mail "[email protected]";
Unattended-Upgrade::MailReport "on-change"; // always | only-on-error | on-change
// Logging
Unattended-Upgrade::SyslogEnable "true";
// Bandwidth limit in KB/s
// Acquire::http::Dl-Limit "512";
Holding packages¶
sudo apt-mark hold linux-image-amd64 linux-headers-amd64
apt-mark showhold
Held packages are skipped by unattended-upgrades.
When it runs: systemd timers¶
APT::Periodic is evaluated by two timers:
| Timer | Does |
|---|---|
apt-daily.timer |
apt update + downloads (twice daily, randomized up to 12h) |
apt-daily-upgrade.timer |
Runs unattended-upgrade (~06:00, randomized up to 60 min) |
Move the upgrade window into your maintenance slot:
sudo systemctl edit apt-daily-upgrade.timer
[Timer]
OnCalendar=
OnCalendar=*-*-* 02:00
RandomizedDelaySec=30m
Persistent=true
sudo systemctl daemon-reload
systemctl list-timers 'apt-daily*'
Test and inspect¶
sudo unattended-upgrade --dry-run --debug
sudo unattended-upgrade -v # run it now
less /var/log/unattended-upgrades/unattended-upgrades.log
less /var/log/unattended-upgrades/unattended-upgrades-dpkg.log
zgrep -h ' install \| upgrade ' /var/log/dpkg.log* | tail
journalctl -u apt-daily-upgrade.service
Distro-specific notes¶
- Ubuntu
needrestart: installed by default since 22.04 and runs after apt. In unattended runs it's non-interactive; configure it to auto-restart services (see Restarting services). - Ubuntu Livepatch:
sudo pro enable livepatch— rebootless kernel security fixes (Ubuntu Pro). - Ubuntu release upgrades are never done by unattended-upgrades.
do-release-upgradestays manual; setPrompt=neverin/etc/update-manager/release-upgradeson servers to silence the nag. - Proxmox VE: auto-upgrading the security pocket of the Debian base is common, but do not blindly auto-upgrade
pve-*,proxmox-*, orzfs*packages on a cluster; use the blacklist and patch cluster nodes one at a time. - Debian
-backportsis never selected unless you add it explicitly.
Fedora: dnf5 automatic¶
Fedora 41 and later use DNF5, and the automatic updater is a DNF5 plugin with a slightly different layout from the old dnf-automatic.
sudo dnf install dnf5-plugin-automatic
Configuration¶
Defaults live in /usr/share/dnf5/dnf5-plugins/automatic.conf. Put only your overrides in /etc/dnf/automatic.conf:
[commands]
upgrade_type = security # default | security
download_updates = yes
apply_updates = yes
random_sleep = 0 # the timer already randomizes
network_online_timeout = 60
reboot = when-needed # never | when-changed | when-needed
reboot_command = "shutdown -r +5 'Rebooting after applying package updates'"
[emitters]
emit_via = stdio,motd # stdio | motd | email | command_email | command
# emit_via = email
[email]
email_from = [email protected]
email_to = [email protected]
email_host = localhost
[base]
# Any dnf.conf option, e.g. exclude kernels:
# excludepkgs = kernel*
reboot = when-needed reboots only if a core package (kernel, glibc, systemd, etc.) was updated; when-changed reboots if anything changed.
The email emitter in DNF5 talks SMTP through libcurl; Fedora's minimal libcurl lacks SMTP, so if you see errors run sudo dnf swap libcurl-minimal libcurl, or use command_email with a local mail binary.
Timer¶
DNF5 merged the old dnf-automatic-download/-install/-notifyonly timers into a single timer that obeys the config file:
sudo systemctl enable --now dnf5-automatic.timer # dnf-automatic.timer is an alias
systemctl list-timers dnf5-automatic.timer
sudo systemctl edit dnf5-automatic.timer # change OnCalendar if needed
Test and logs¶
sudo dnf automatic --timer=no # run now (or: dnf automatic --installupdates)
journalctl -u dnf5-automatic.service
less /var/log/dnf5.log
dnf history list | head
Fedora caveats¶
- Fedora moves fast; full auto-upgrade on a Fedora server is fine for homelabs, riskier for production.
upgrade_type = securityrelies on Fedora's updateinfo metadata, which Fedora does provide. - Fedora CoreOS / Atomic desktops don't use dnf-automatic at all — they use
rpm-ostreewith Zincati (CoreOS) orrpm-ostreed-automatic.timer(Silverblue/Kinoite) for atomic, rollback-able updates. - Release upgrades (
dnf system-upgrade) are always manual.
RHEL, AlmaLinux, Rocky, Oracle Linux, CentOS Stream: dnf-automatic¶
RHEL 8, 9 and 10 (and rebuilds) still use DNF 4 and the classic dnf-automatic package.
sudo dnf install dnf-automatic
Configuration: /etc/dnf/automatic.conf¶
[commands]
upgrade_type = security # default | security
random_sleep = 0
network_online_timeout = 60
download_updates = yes
apply_updates = yes
# Newer dnf-automatic builds (RHEL 9.x recent / 10) support:
reboot = when-needed # never | when-changed | when-needed
reboot_command = "shutdown -r +5 'Rebooting after applying package updates'"
[emitters]
system_name = None # defaults to hostname
emit_via = motd,email # stdio | motd | email | command | command_email
[email]
email_from = [email protected]
email_to = [email protected]
email_host = localhost
[base]
debuglevel = 1
# exclude = kernel* postgresql*
If your build doesn't recognise reboot, handle reboots separately (see Detecting and scheduling reboots).
Timers¶
DNF 4 ships four timers; enable exactly one:
| Timer | Behaviour |
|---|---|
dnf-automatic.timer |
Follows automatic.conf (download_updates / apply_updates) |
dnf-automatic-notifyonly.timer |
Only reports available updates |
dnf-automatic-download.timer |
Downloads, doesn't install |
dnf-automatic-install.timer |
Downloads and installs (overrides apply_updates) |
sudo systemctl enable --now dnf-automatic.timer
sudo systemctl edit dnf-automatic.timer
[Timer]
OnCalendar=
OnCalendar=Sat *-*-* 03:00
RandomizedDelaySec=45m
Persistent=true
Security-only, done right¶
upgrade_type = security depends on updateinfo (errata) metadata in the repo:
- RHEL — full errata with severities. You can be stricter with the CLI equivalent:
dnf upgrade --security --sec-severity=Critical,Important. - AlmaLinux, Rocky, Oracle Linux — publish updateinfo, so security filtering works.
- CentOS Stream — historically lacks reliable security metadata; assume "security" means "nothing" and use
default. - EPEL — has updateinfo, but quality varies.
Check what would be applied:
dnf updateinfo summary
dnf updateinfo list --security
dnf upgrade --security --assumeno
Version locking¶
sudo dnf install 'dnf-command(versionlock)' # python3-dnf-plugin-versionlock
sudo dnf versionlock add postgresql-server kernel-5.14.0-503*
dnf versionlock list
Logs¶
journalctl -u dnf-automatic.service
less /var/log/dnf.log /var/log/dnf.rpm.log
dnf history info last
Vendor notes¶
- RHEL: Red Hat Insights / Satellite can orchestrate patching with approval workflows; Satellite content views give you frozen, promoted snapshots (Dev → QA → Prod), which pairs very well with dnf-automatic on clients (auto-apply whatever has been promoted).
- Oracle Linux: Ksplice offers rebootless kernel and user-space (glibc, OpenSSL) patching with an Oracle Linux Premier Support subscription.
- AlmaLinux / Rocky: same as RHEL minus Satellite/Insights; Foreman + Katello is the open-source equivalent for content views.
Amazon Linux 2023¶
AL2023 uses DNF and versioned, locked repositories: by default a host stays on the repository snapshot it launched with (releasever lock). Running dnf upgrade alone won't move you to newer packages.
dnf check-release-update # is a newer repo version available?
sudo dnf upgrade --releasever=latest # move to the latest snapshot
# or pin to a specific one:
sudo dnf upgrade --releasever=2023.9.20251105
Unattended options:
- Immutable approach (AWS-recommended): bake a new AMI from the latest release and replace instances (Auto Scaling instance refresh, EC2 Image Builder).
- In-place with dnf-automatic:
bash
sudo dnf install dnf-automatic
# /etc/dnf/automatic.conf: apply_updates = yes, upgrade_type = security
To let it follow new releases, make the release float:
bash
echo latest | sudo tee /etc/dnf/vars/releasever
sudo systemctl enable --now dnf-automatic.timer
- AWS Systems Manager Patch Manager: patch baselines (auto-approve after N days, severity filters), maintenance windows, and compliance reports across EC2 and hybrid nodes — the AWS-native way to do this at scale.
Amazon Linux 2 (EOL mid-2026) used yum-cron / yum update --security; migrate to AL2023.
SUSE Linux Enterprise and openSUSE¶
SUSE has several models depending on whether the system is a traditional read-write install or an immutable/transactional one.
Traditional SLES / openSUSE Leap: zypper on a systemd timer¶
There's no "zypper-automatic" equivalent shipped by default on all versions, so a small service + timer is the standard approach.
/etc/systemd/system/zypper-auto-patch.service:
[Unit]
Description=Automatic zypper patch
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStartPre=/usr/bin/zypper --non-interactive refresh
# Security patches only (SLES/Leap publish patch metadata):
ExecStart=/usr/bin/zypper --non-interactive patch --category security --auto-agree-with-licenses
# Or all patches: zypper --non-interactive patch --auto-agree-with-licenses
# Or all packages: zypper --non-interactive update --auto-agree-with-licenses
# Exit code 103 = zypper updated itself and needs a re-run; 102 = reboot needed
SuccessExitStatus=0 100 101 102 103
/etc/systemd/system/zypper-auto-patch.timer:
[Unit]
Description=Run zypper patch daily
[Timer]
OnCalendar=*-*-* 03:00
RandomizedDelaySec=45m
Persistent=true
[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now zypper-auto-patch.timer
Note that zypper patch may need two passes when the first one updates the package manager stack itself (exit code 103). Either run the service twice or add a second ExecStart= line.
Useful commands:
zypper list-patches --category security
zypper patch-check
zypper al postgresql* # add lock (exclude)
zypper ll # list locks
zypper needs-rebooting # exit code 102 if reboot needed
zypper ps -s # processes using deleted files
Btrfs + Snapper (default root FS on SUSE): every zypper transaction creates pre/post snapshots, so a bad unattended update can be rolled back with snapper rollback or by booting an older snapshot from GRUB.
openSUSE os-update: on Tumbleweed (and newer releases) the os-update package provides os-update.timer that runs the right update command for the system type, with configurable reboot behaviour via rebootmgr. Check whether your release packages it before rolling your own timer.
Transactional systems: SL Micro, openSUSE MicroOS / Leap Micro, transactional-server role¶
These have a read-only root and update into a new Btrfs snapshot that becomes active on next boot — atomic and trivially rollback-able.
systemctl status transactional-update.timer # enabled by default
sudo systemctl edit transactional-update.timer # change schedule
# /etc/transactional-update.conf
# UPDATE_METHOD=up # "up" = full update, "patch" = patches only (SLE)
# REBOOT_METHOD=rebootmgr # auto | rebootmgr | notify | systemd | kured | none
rebootmgr enforces maintenance windows and can coordinate cluster-wide reboots via etcd locks:
rebootmgrctl set-strategy maint-window
rebootmgrctl set-window 03:30 1h30m
rebootmgrctl status
SLES 16 and SUSE Multi-Linux Manager¶
For managed fleets, SUSE Multi-Linux Manager (formerly SUSE Manager; upstream Uyuni) handles content lifecycle (frozen channel snapshots), action chains, and scheduled patching for SUSE, RHEL-family and Ubuntu clients.
Arch Linux¶
Arch officially discourages unattended upgrades: it's rolling-release, occasionally requires manual intervention announced on the news page, and partial upgrades are unsupported. If you run Arch on servers anyway, the sane patterns are:
1. Download only, upgrade manually (safest):
# /etc/systemd/system/pacman-download.service
[Unit]
Description=Download pacman updates
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/pacman -Syuw --noconfirm
# /etc/systemd/system/pacman-download.timer
[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.target
Then pacman -Su after reading https://archlinux.org/news/.
2. Fully automatic (homelab-only):
ExecStart=/usr/bin/pacman -Syu --noconfirm
Mitigate with:
- Snapshots:
snap-pac(Snapper pre/post hooks on Btrfs) ortimeshift-autosnap. - Ignore risky packages in
/etc/pacman.conf:IgnorePkg = linux linux-headers nvidia* postgresql*. - Keep keys fresh:
archlinux-keyring-wkd-sync.timeris enabled by default on modern installs; old installs that skip months may needpacman -Sy archlinux-keyringfirst. - Use the
linux-ltskernel on servers. - Mirror freshness:
reflector.timerto keep a working mirrorlist. .pacnewfiles are never merged automatically — check withpacdiff.
Do not use AUR helpers (yay, paru) unattended.
Alpine Linux¶
Alpine has no updater daemon; use cron (BusyBox crond is enabled by default) or OpenRC with a periodic script.
# /etc/periodic/daily/apk-upgrade
#!/bin/sh
set -eu
apk update -q
apk upgrade --available -q 2>&1 | logger -t apk-upgrade
# kernel changed? modules for the running kernel disappear when it's replaced
if [ ! -d "/lib/modules/$(uname -r)" ]; then
touch /run/reboot-required
fi
chmod +x /etc/periodic/daily/apk-upgrade
rc-update add crond default && rc-service crond start
Notes:
- Pin packages with
apk add 'postgresql16<16.5'or by pinning repository tags in/etc/apk/world. - Stay within one branch (
v3.22, etc.) in/etc/apk/repositoriesfor stable-only updates; never point production atedgeunattended. apk upgrade --availablealso replaces packages that moved repos; plainapk upgradeis more conservative.- Branch bumps (
v3.21→v3.22) are a manual edit of/etc/apk/repositories. - For diskless/
lbusetups, rememberlbu commitor the upgrade won't persist across reboots.
Legacy: yum-cron (RHEL/CentOS 7)¶
Only for systems you haven't migrated yet (RHEL 7 is in ELS; CentOS 7 is EOL and receives no updates at all).
yum install yum-cron
# /etc/yum/yum-cron.conf
# update_cmd = security
# apply_updates = yes
# emit_via = email
systemctl enable --now yum-cron
Restarting services after updates¶
A patched OpenSSL does nothing for a process that still has the old .so mapped. Each family has a tool to find and (optionally) restart those processes.
| Distro | Tool | Command |
|---|---|---|
| Debian/Ubuntu | needrestart |
needrestart -r a (auto), -r l (list) |
| Debian (alt.) | checkrestart (debian-goodies) |
checkrestart |
| RHEL/Fedora/Alma/Rocky | dnf needs-restarting |
dnf needs-restarting -s (services), -r (reboot) |
| SUSE | zypper ps |
zypper ps -s |
| Arch | needrestart (AUR/extra) or lsof |
lsof +L1 \| grep DEL |
| Any | lsof |
lsof -n \| grep -E 'DEL\|deleted' \| grep -E '\.so' |
needrestart (Ubuntu default) — automatic mode¶
/etc/needrestart/conf.d/50-auto.conf:
# a = automatic, l = list only, i = interactive
$nrconf{restart} = 'a';
# Don't touch these
$nrconf{override_rc}{qr(^docker)} = 0;
$nrconf{override_rc}{qr(^containerd)} = 0;
$nrconf{override_rc}{qr(^kubelet)} = 0;
dnf-based: restart affected services after each run¶
# /etc/systemd/system/dnf-automatic.service.d/restart.conf
[Service]
ExecStartPost=/bin/sh -c 'for s in $(dnf needs-restarting -s 2>/dev/null); do case "$s" in sshd*|docker*|containerd*|kubelet*) ;; *) systemctl try-restart "$s";; esac; done'
(On Fedora with dnf5 the drop-in goes under dnf5-automatic.service.d/.)
Detecting and scheduling reboots¶
| Distro | "Reboot needed?" signal |
|---|---|
| Debian/Ubuntu | /var/run/reboot-required exists (lists packages in /var/run/reboot-required.pkgs) |
| RHEL/Fedora family | dnf needs-restarting -r → exit code 1 |
| SUSE | zypper needs-rebooting → exit code 102 (or /run/reboot-needed) |
| Arch | Running kernel ≠ installed: [ -d "/usr/lib/modules/$(uname -r)" ] \|\| echo reboot |
| Alpine | [ -d "/lib/modules/$(uname -r)" ] \|\| echo reboot (no built-in flag) |
Generic reboot window timer¶
Decouple installing (nightly) from rebooting (weekly window):
# /usr/local/sbin/reboot-if-needed
#!/bin/sh
needs=0
[ -f /var/run/reboot-required ] && needs=1
command -v dnf >/dev/null && ! dnf needs-restarting -r >/dev/null 2>&1 && needs=1
command -v zypper >/dev/null && { zypper needs-rebooting >/dev/null 2>&1; [ $? -eq 102 ] && needs=1; }
[ "$needs" -eq 1 ] && logger -t reboot-if-needed "Reboot required, rebooting" && systemctl reboot
exit 0
# /etc/systemd/system/reboot-if-needed.timer
[Timer]
OnCalendar=Sun *-*-* 04:00
RandomizedDelaySec=30m
[Install]
WantedBy=timers.target
Kubernetes nodes¶
Don't let the OS reboot a node on its own. Use kured (Kubernetes Reboot Daemon): it watches for /var/run/reboot-required (or a custom sentinel command such as dnf needs-restarting -r), takes a cluster-wide lock, cordons + drains, reboots, and uncordons — one node at a time, inside a configurable window.
helm repo add kubereboot https://kubereboot.github.io/charts
helm install kured kubereboot/kured -n kube-system \
--set configuration.startTime=02:00 \
--set configuration.endTime=05:00 \
--set configuration.timeZone=America/Toronto \
--set configuration.rebootSentinelCommand="sh -c '! dnf needs-restarting -r'"
For Docker Swarm, drain the node (docker node update --availability drain <node>) before rebooting and set it back to active after, one manager at a time to keep quorum.
Kernel livepatching¶
Livepatching applies critical kernel security fixes in memory, so you can stretch reboots to your normal maintenance cadence.
| Distro | Service | Notes |
|---|---|---|
| Ubuntu | Canonical Livepatch | pro enable livepatch; Ubuntu Pro (free for 5 machines) |
| RHEL | kpatch | dnf install kpatch kpatch-dnf; dnf kpatch auto to auto-subscribe to livepatches for the running kernel |
| AlmaLinux / Rocky | kpatch-style via TuxCare (commercial) | |
| Oracle Linux | Ksplice | Kernel + user-space, Premier Support |
| SUSE | SUSE Linux Enterprise Live Patching | Extension subscription; kernel-livepatch-* packages delivered via zypper patch |
| Debian / others | TuxCare KernelCare (commercial) |
Livepatching does not replace reboots — it only covers selected CVEs, and patches stop after a kernel's livepatch window (typically about a year). Keep a regular reboot cadence.
Fleet orchestration¶
Per-host timers are fine for a handful of machines. For a fleet, you want rings, health gates and reporting.
Ansible: rolling patch with health check¶
- name: Rolling OS patch
hosts: web
become: true
serial: "25%"
max_fail_percentage: 0
tasks:
- name: Patch Debian/Ubuntu
ansible.builtin.apt:
upgrade: dist
update_cache: true
autoremove: true
when: ansible_os_family == "Debian"
- name: Patch RHEL family (security only)
ansible.builtin.dnf:
name: "*"
state: latest
security: true
when: ansible_os_family == "RedHat"
- name: Patch SUSE
community.general.zypper:
name: "*"
state: latest
type: patch
when: ansible_os_family == "Suse"
- name: Reboot needed? (Debian)
ansible.builtin.stat: { path: /var/run/reboot-required }
register: rr
- name: Reboot needed? (dnf)
ansible.builtin.command: dnf needs-restarting -r
register: nr
failed_when: false
changed_when: false
when: ansible_os_family == "RedHat"
- name: Reboot
ansible.builtin.reboot: { reboot_timeout: 900 }
when: rr.stat.exists | default(false) or (nr.rc | default(0)) == 1
- name: Health gate
ansible.builtin.uri:
url: "http://{{ inventory_hostname }}/healthz"
status_code: 200
retries: 10
delay: 6
Other options¶
| Tool | Scope |
|---|---|
| Red Hat Satellite / Foreman + Katello | RHEL family; content views, errata, remote execution |
| SUSE Multi-Linux Manager / Uyuni | SUSE, RHEL family, Ubuntu, Debian |
| Canonical Landscape | Ubuntu |
| Azure Update Manager | Linux on Azure and Azure Arc (any cloud / on-prem) |
| AWS Systems Manager Patch Manager | EC2 + hybrid nodes |
| GCP VM Manager (OS patch management) | GCE |
Pick one controller per host — don't combine a vendor patch manager with a local unattended timer that installs on a different schedule.
Monitoring¶
At minimum, alert on:
- Last successful patch run older than N days (parse logs, or
dnf history//var/log/apt/history.logtimestamps). - Reboot required for more than N days.
- Number of pending security updates > 0 for more than N days.
node_exporter's textfile collector plus a small script (e.g. the apt_info.py / yum.sh scripts from prometheus-community/node-exporter-textfile-collector-scripts) gives you apt_upgrades_pending, node_reboot_required and friends for Grafana dashboards and Alertmanager rules.
Quick reference¶
| Distro | Tool | Enable | Config | Security-only | Auto reboot |
|---|---|---|---|---|---|
| Debian | unattended-upgrades | dpkg-reconfigure -plow unattended-upgrades |
/etc/apt/apt.conf.d/50unattended-upgrades |
Default (Debian-Security origin) | Automatic-Reboot "true" |
| Ubuntu | unattended-upgrades | Enabled by default | same | Default (-security pocket) |
same |
| Fedora 41+ | dnf5 automatic | systemctl enable --now dnf5-automatic.timer |
/etc/dnf/automatic.conf |
upgrade_type = security |
reboot = when-needed |
| RHEL/Alma/Rocky/OL 8–10 | dnf-automatic | systemctl enable --now dnf-automatic.timer |
/etc/dnf/automatic.conf |
upgrade_type = security |
reboot = (newer builds) or external |
| Amazon Linux 2023 | dnf-automatic / SSM | as RHEL, plus releasever |
/etc/dnf/automatic.conf |
upgrade_type = security |
external / SSM |
| SLES / Leap | zypper + timer (or os-update) |
custom timer | unit file | zypper patch --category security |
external / rebootmgr |
| SL Micro / MicroOS | transactional-update | enabled by default | /etc/transactional-update.conf |
UPDATE_METHOD=patch |
REBOOT_METHOD= |
| Arch | pacman + timer | custom timer | unit file | n/a | external (not recommended) |
| Alpine | apk + crond | /etc/periodic/daily/ |
script | n/a | external |
| Fedora CoreOS | Zincati | enabled by default | /etc/zincati/config.d/ |
n/a | built in (update strategies) |