apt_downloaded_package_files
apt keeps every package file it downloads, the .deb files, in its
archives directory, /var/cache/apt/archives/, after it installed them.
Over months of updates, downloaded package files can fill a small disk.
apt_downloaded_package_files deletes the downloaded package files with
apt-get clean. Installed packages stay as they are; apt downloads a
package file again when it needs one.
Inputs
state(absent; required): the only state: apt-get clean deletes every file in apt's archives directory and in its partial/ directory, and apt's two package list caches, which the next apt command builds again; installed packages stay as they are
Outputs
The node task's result holds these fields. A later node task reads them as .node_tasks.<id>.<field>, where <id> is the node task's id.
statuschangereasonvalue.deleted_package_filesvalue.deleted_bytes
What a dryrun reports
Deletes nothing; reports the number of package files and their bytes, or unchanged when the archives directory holds none; not_checked while apt-get is missing.
Retries and time limits
Bounded automatic retries by default; retry: false turns them off.
The node task takes the time limits time_limit and time_limit_per_try; without them, the project's node_task_defaults apply. mmx describe-module task describes the settings every node task accepts.
Examples
Delete the package files that apt downloaded
- apt_downloaded_package_files:
state: absent
On the node, MMX asks apt for the archives directory with apt-config.
MMX then lists package files in the archives directory and the archives
subdirectory partial/. apt keeps downloads that did not finish in
partial/. If MMX finds package files in the archives directory or
partial/, MMX runs apt-get clean.
MMX reads the archives directory and partial/ again and reports which
package files are gone:
changed — deleted 142 package files totaling 312.6 MiB (327784448 bytes) from /var/cache/apt/archives/
value.deleted_package_files holds the number of files and
value.deleted_bytes their bytes. A dryrun deletes nothing and reports the
files a run would delete. When neither the archives directory nor partial/
contains package files, the node task is unchanged and MMX skips
apt-get clean.
How it works
- What
apt-get cleandeletes.apt-get cleandeletes every file in the archives directory except apt'slock, and every file inpartial/.apt-get cleanalso deletes apt's two caches of the package lists:/var/cache/apt/pkgcache.binandsrcpkgcache.bin. The next apt command builds the two package-list caches again in a few seconds. The package lists themselves, in/var/lib/apt/lists/, stay, so noapt-get updateis needed afterwards. - apt's lock.
apt-get cleantakes the locks of the archives directory and of the package lists, and fails at once while another apt holds one, such as apt's daily timer or an installation by hand. MMX then tries again every two seconds for up to a minute, asapt_packagedoes before it refreshes the package lists. If an apt lock stays held, MMX fails the node task and names the held lock in the error. - The archives directory is the one that apt's settings name
(
Dir::Cache::archives),/var/cache/apt/archives/unless a setting moves it.
Errors and what they mean
| The reason holds | What the error means, and what to do |
|---|---|
another apt process still holds the lock on the downloaded package files after 1m0s |
MMX could not acquire the apt lock during the one-minute wait. Run MMX again when the apt command holding the lock finishes. |
apt-get is not installed |
The node does not install its packages with apt. A dryrun reports the node task not checked. |
Tested on
Distributions: Debian 12 and 13, Ubuntu 24.04 and 26.04.
The suite tests/integration/routine_fixes.py downloads package files with
apt-get download, holds apt's lock for a moment while the node task runs,
and checks the dryrun, the run, and the archives directory on the node, on Debian 12 and 13 and Ubuntu 24.04 and 26.04. The
validation record has the latest results.
Why it works this way
state: absentis written. The node task reads as what it does: the package files are absent afterwards. It is the only state.- apt-get does the deleting. It is apt's own cleanup and knows which files are apt's; MMX decides the result from the directory before and after, not from what apt prints.
- It waits for apt's lock for the reason
apt_packagedoes: apt's daily timer and cloud-init hold it just after a server first boots, andapt-get cleandoes not wait by itself.
This page is docs/reference/modules/apt_downloaded_package_files.md in the MMX repository.