apt

Collection: builtin

Full Name: parallax.builtin.apt

Aliases: ansible.builtin.apt, apt

Synopsis

Install, upgrade and remove packages with apt on Debian and Ubuntu

Parameters

NameTypeRequiredDefaultDescription
namelistPackage name, or package specifier with version
statestringpresentDesired state of the package Choices: absent, build-dep, fixed, latest, present
update_cacheboolfalseRun apt-get update before the operation
update_cache_retriesint5Number of retries if update_cache fails
update_cache_retry_max_delayint12Max delay between retries in seconds
cache_valid_timeint0Update cache if older than this many seconds
allow_downgradeboolfalseAllow downgrades of packages
allow_unauthenticatedboolfalseIgnore if packages cannot be authenticated
allow_change_held_packagesboolfalseAllow apt to upgrade held packages
debstringPath to a .deb package on the remote machine
default_releasestringDefault release to install packages from
dpkg_optionsstringforce-confdef,force-confoldAdd dpkg options to apt command
autoremoveboolfalseRemove unused dependency packages
autocleanboolfalseCleans the local repository of packages
cleanboolfalseRun apt-get clean
install_recommendsbooltrueInstall recommended packages
forceboolfalseForce usage of apt instead of apt-get
force_apt_getboolfalseForce usage of apt-get instead of apt
upgradestringnoUpgrade all packages to latest version Choices: no, yes, safe, full, dist
only_upgradeboolfalseOnly upgrade a package if installed
purgeboolfalsePurge package configuration files
fail_on_autoremoveboolfalseFail if packages would be autoremoved
lock_timeoutint60How long to wait for lock (seconds)
policy_rc_dint0Force policy-rc.d return code

Example

- name: Install nginx and refresh the package index first
  apt:
    name: nginx
    state: present
    update_cache: true
    cache_valid_time: 3600

- name: Remove a package and its unused dependencies
  apt:
    name: apache2
    state: absent
    purge: true
    autoremove: true