+

Search Tips   |   Advanced Search

ansible.builtin.apt - Manages apt-packages

This module is part of ansible-base and included in all Ansible installations. In most cases, you can use the short module name apt even without specifying the collections: keyword. Despite that, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.

New in version 0.0.2: of ansible.builtin


Synopsis


Requirements

The below requirements are needed on the host that executes this module.


Parameters

Parameter Choices/Defaults Comments

allow_unauthenticated

boolean

  • no ←
  • yes

Ignore if packages cannot be authenticated. This is useful for bootstrapping environments that manage their own apt-key setup.

allow_unauthenticated is only supported with state: install/present

autoclean

boolean

  • no ←
  • yes

If yes, cleans the local repository of retrieved package files that can no longer be downloaded.

autoremove

boolean

  • no ←
  • yes

If yes, remove unused dependency packages for all module states except build-dep. It can also be used as the only option.

Previous to version 2.4, autoclean was also an alias for autoremove, now it is its own separate command. See documentation for further information.

cache_valid_time

string

Default:

0

Update the apt cache if its older than the cache_valid_time. This option is set in seconds.

As of Ansible 2.4, if explicitly set, this sets update_cache=yes.

deb

string

Path to a .deb package on the remote machine.

If :// in the path, ansible will attempt to download deb before installing. (Version added 2.1)

Requires the xz-utils package to extract the control file of the deb package to install.

default_release

string

Corresponds to the -t option for apt and sets pin priorities

dpkg_options

string

Default:

"force-confdef,force-confold"

Add dpkg options to apt command. Defaults to '-o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold"'

Options should be supplied as comma separated list

force

boolean

  • no ←
  • yes

Corresponds to the --force-yes to apt-get and implies allow_unauthenticated: yes

This option will disable checking both the packages' signatures and the certificates of the web servers they are downloaded from.

This option *is not* the equivalent of passing the -f flag to apt-get on the command line

**This is a destructive operation with the potential to destroy your system, and it should almost never be used.** Please also see man apt-get for more information.

force_apt_get

boolean

  • no ←
  • yes

Force usage of apt-get instead of aptitude

install_recommends

boolean

  • no
  • yes

Corresponds to the --no-install-recommends option for apt. yes installs recommended packages. no does not install recommended packages. By default, Ansible will use the same defaults as the operating system. Suggested packages are never installed.


aliases: install-recommends

name

list / elements=string

A list of package names, like foo, or package specifier with version, like foo=1.0. Name wildcards (fnmatch) like apt* and version wildcards like foo=1.0* are also supported.


aliases: package, pkg

only_upgrade

boolean

  • no ←
  • yes

Only upgrade a package if it is already installed.

policy_rc_d

integer

Force the exit code of /usr/sbin/policy-rc.d.

For example, if policy_rc_d=101 the installed package will not trigger a service start.

If /usr/sbin/policy-rc.d already exist, it is backed up and restored after the package installation.

If null, the /usr/sbin/policy-rc.d isn't created/changed.

purge

boolean

  • no ←
  • yes

Will force purging of configuration files if the module state is set to absent.

state

string

  • absent
  • build-dep
  • latest

  • present ←
  • fixed

Indicates the desired package state. latest ensures that the latest version is installed. build-dep ensures the package build dependencies are installed. fixed attempt to correct a system with broken dependencies in place.

update_cache

boolean

  • no
  • yes

Run the equivalent of apt-get update before the operation. Can be run as part of the package installation or as a separate step.

Default is not to update the cache.

update_cache_retries

integer

Default:

5

Amount of retries if the cache update fails. Also see update_cache_retry_max_delay.

update_cache_retry_max_delay

integer

Default:

12

Use an exponential backoff delay for each retry (see update_cache_retries) up to this max delay in seconds.

upgrade

string

  • dist
  • full

  • no ←
  • safe
  • yes

If yes or safe, performs an aptitude safe-upgrade.

If full, performs an aptitude full-upgrade.

If dist, performs an apt-get dist-upgrade.

Note: This does not upgrade a specific package, use state=latest for that.

Note: Since 2.4, apt-get is used as a fall-back if aptitude is not present.



Notes


Examples


Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description

cache_update_time

integer

success, in some cases

time of the last cache update (0 if unknown)

Sample:

1425828348000

cache_updated

boolean

success, in some cases

if the cache was updated or not

Sample:

True

stderr

string

success, when needed

error output from apt

Sample:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to ...

stdout

string

success, when needed

output from apt

Sample:

Reading package lists... Building dependency tree... Reading state information... The following extra packages will be installed: apache2-bin ...




Authors