Playbook
Clean Disk Space
Free disk space from caches, old logs and unused packages, without touching your data.
Category
Maintenance
Time limit per server
30 minutes
Temporary failures
Retried automatically, up to 1 time
Version
1.0
Supported systems
Ubuntu 22.04+, Debian 12+, RHEL-compatible 8+ (AlmaLinux, Rocky Linux, RHEL, CentOS Stream, Oracle Linux), Amazon Linux 2023+. Still runs on Ubuntu 20.04, Debian 11 and Amazon Linux 2, which are past the end of standard support.
Options
As they appear on the run form, with their defaults.
Journal size limit
One choice
Older journal entries are removed until the journal fits.
- Leave the journal alone
- 100 MB
- 250 MB
- 500 MB
- 1 GB
Default: 500 MB
Delete rotated logs older than
One choice
- Keep all rotated logs
- 7 days
- 14 days
- 30 days
Default: 30 days
Remove unused packages
On or off
Leftover dependencies, including old kernels and disabled snap revisions.
Default: Off
Clean Docker
On or off
Untagged images and the build cache. Containers, volumes and tagged images are kept.
Default: Off
When to use it
When a disk is filling up, when monitoring reports high disk usage, or as routine maintenance. It removes only what the system can recreate or no longer uses, and it works on a server whose disk is completely full.
Choosing the options
Journal size limit — the systemd journal is trimmed until it fits the size you choose, removing the oldest entries first (journalctl --vacuum-size). 500 MB keeps several weeks of logs on most servers. Choose Leave the journal alone if you keep logs for an audit.
Delete rotated logs older than — deletes log files in /var/log that have already been rotated (compressed .gz, .xz, .bz2, .zst files and numbered files such as syslog.1) and are older than the age you choose. Logs still being written are never deleted.
Remove unused packages — removes packages that were installed as dependencies of something since removed, including old kernels, and disabled snap revisions. On yum-based servers "unused" means nothing depends on the package, which can include software installed on purpose: run a dry run first and review the list.
Clean Docker — removes untagged Docker images and the build cache. Containers, volumes and tagged images are kept.
What it does on the server
- Records free space on
/. - Deletes downloaded package files from the package manager's cache.
- Applies each option you chose, reporting how much each one freed.
- Records free space again and lists the largest directories, so you can see where the remaining space is used.
It never touches /home, /var/www, /srv, /opt, databases, containers or Docker volumes.
After the run
Compare the free space before and after. If the disk is still full, the largest-directories list at the end shows where to look. Application uploads, database files and backups kept on the server are the usual causes, and they need a decision from you.
Common problems
"Docker is installed but its daemon is not answering, so its images were not cleaned." — Start Docker with Restart Services (service docker), then run this playbook again.
The disk is still almost full after the run — The space is used by your own data. Check the largest directories in the output. Moving backups off the server, with Backups storing them in your own bucket, is the usual fix.