Skip to main content

apt

apt module

Use the apt module to install, upgrade, or remove Debian packages using apt-get. It also supports updating the package cache via 'update_cache'.

Examples

- name: Ensure curl is present
apt:
name: curl
state: present

- name: Install multiple packages
apt:
name: [curl, git]

- name: Update apt cache
apt:
update_cache: true

- name: Ensure package is absent
apt:
name: telnet
state: absent

Notes

  • 'state: latest' will attempt to upgrade packages to the latest available version.
  • You can also specify 'pkg' instead of 'name' (alias).

Module Capabilities

  • Has Revert: false
  • Provides Variables: None

Inputs

ParameterTypeDescriptionRequiredDefaultChoices
nameanyName of the package(s) to operate on. Can be a string or a list of strings.false
statestringDesired package state.falsepresentpresent, absent, latest
update_cacheboolRun apt-get update before the operation.falsefalsetrue, false

Outputs

FieldTypeDescription
packages[string]Packages operated on
statestringFinal state (installed, removed, updated)
versions[string]Versions installed/removed (if applicable)

Parameter aliases

  • pkg → name