Quiz Entry - updated: 2026.10.30
What is the difference between the ansible.builtin.apt and ansible.builtin.package modules?
apt talks directly to Debian/Ubuntu's apt package manager and offers all its options; package is a generic front end that detects the host's package manager (apt, dnf, ...) and passes the task to it, supporting only the options all of them share.
ansible.builtin.package |
ansible.builtin.apt |
|
|---|---|---|
| Works on | Any OS with a supported package manager | Debian, Ubuntu and derivatives |
| How | Uses facts to pick the right module, then proxies to it | Calls apt directly |
| Options | Common subset: name, state, use |
Everything apt can do: update_cache, upgrade, cache_valid_time, deb, ... |
| Choose when | One playbook must run on mixed distributions | You need apt-specific features |
The trade-off is portability against power. The Apache lab uses package so the task reads the same everywhere. The extended example switches to apt, which can for instance refresh the package cache first (update_cache: true). Note that package doesn't translate package names: Apache is apache2 on Debian and httpd on RHEL, so the name may still differ per OS.
Go deeper:
package module (official docs) — "acts as a proxy to the underlying package manager module".
apt module (official docs) — all apt-specific options.