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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| name | list | Package name, or package specifier with version | ||
| state | string | present | Desired state of the package Choices: absent, build-dep, fixed, latest, present | |
| update_cache | bool | false | Run apt-get update before the operation | |
| update_cache_retries | int | 5 | Number of retries if update_cache fails | |
| update_cache_retry_max_delay | int | 12 | Max delay between retries in seconds | |
| cache_valid_time | int | 0 | Update cache if older than this many seconds | |
| allow_downgrade | bool | false | Allow downgrades of packages | |
| allow_unauthenticated | bool | false | Ignore if packages cannot be authenticated | |
| allow_change_held_packages | bool | false | Allow apt to upgrade held packages | |
| deb | string | Path to a .deb package on the remote machine | ||
| default_release | string | Default release to install packages from | ||
| dpkg_options | string | force-confdef,force-confold | Add dpkg options to apt command | |
| autoremove | bool | false | Remove unused dependency packages | |
| autoclean | bool | false | Cleans the local repository of packages | |
| clean | bool | false | Run apt-get clean | |
| install_recommends | bool | true | Install recommended packages | |
| force | bool | false | Force usage of apt instead of apt-get | |
| force_apt_get | bool | false | Force usage of apt-get instead of apt | |
| upgrade | string | no | Upgrade all packages to latest version Choices: no, yes, safe, full, dist | |
| only_upgrade | bool | false | Only upgrade a package if installed | |
| purge | bool | false | Purge package configuration files | |
| fail_on_autoremove | bool | false | Fail if packages would be autoremoved | |
| lock_timeout | int | 60 | How long to wait for lock (seconds) | |
| policy_rc_d | int | 0 | Force 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