ansible.builtin.apt (v2.5.6) — module

Manages apt-packages

| "added in version" 0.0.2 of ansible.builtin"

Authors: Matthew Williams (@mgwilliams)

stableinterface | supported by core

Install Ansible via pip

Install with pip install ansible==2.5.6

Description

Manages I(apt) packages (such as for Debian/Ubuntu).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Update repositories cache and install "foo" package
  apt:
    name: foo
    update_cache: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install apache service but avoid starting it immediately
  apt: name=apache2 state=present
  environment:
    RUNLEVLEL: 1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove "foo" package
  apt: name=foo state=absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install the package "foo"
  apt:
    name: foo
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install the version '1.00' of package "foo"
  apt:
    name: foo=1.00
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Update the repository cache and update package "nginx" to latest version using default release squeeze-backport
  apt:
    name: nginx
    state: latest
    default_release: squeeze-backports
    update_cache: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install latest version of "openjdk-6-jdk" ignoring "install-recommends"
  apt:
    name: openjdk-6-jdk
    state: latest
    install_recommends: no
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Upgrade all packages to the latest version
  apt:
    name: "*"
    state: latest
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Update all packages to the latest version
  apt:
    upgrade: dist
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run the equivalent of "apt-get update" as a separate step
  apt:
    update_cache: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Only run "update_cache=yes" if the last one is more than 3600 seconds ago
  apt:
    update_cache: yes
    cache_valid_time: 3600
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Pass options to dpkg on run
  apt:
    upgrade: dist
    update_cache: yes
    dpkg_options: 'force-confold,force-confdef'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install a .deb package
  apt:
    deb: /tmp/mypackage.deb
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install the build dependencies for package "foo"
  apt:
    pkg: foo
    state: build-dep
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install a .deb package from the internet.
  apt:
    deb: https://example.com/python-ppq_0.1-1_all.deb
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove useless packages from the cache
  apt:
    autoclean: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove dependencies that are no longer required
  apt:
    autoremove: yes

Inputs

    
deb:
    description:
    - 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)
    required: false
    version_added: '1.6'
    version_added_collection: ansible.builtin

name:
    aliases:
    - package
    - pkg
    description:
    - A list of package names, like C(foo), or package specifier with version, like C(foo=1.0).
      Name wildcards (fnmatch) like C(apt*) and version wildcards like C(foo=1.0*) are
      also supported.

force:
    default: 'no'
    description:
    - 'Corresponds to the C(--force-yes) to I(apt-get) and implies C(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 C(-f) flag to I(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 C(man apt-get) for more information.'
    type: bool

purge:
    default: 'no'
    description:
    - Will force purging of configuration files if the module state is set to I(absent).
    type: bool

state:
    choices:
    - absent
    - build-dep
    - latest
    - present
    default: present
    description:
    - Indicates the desired package state. C(latest) ensures that the latest version is
      installed. C(build-dep) ensures the package build dependencies are installed.

upgrade:
    choices:
    - dist
    - full
    - 'no'
    - safe
    - 'yes'
    default: 'no'
    description:
    - 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.'
    version_added: '1.1'
    version_added_collection: ansible.builtin

autoclean:
    default: 'no'
    description:
    - If C(yes), cleans the local repository of retrieved package files that can no longer
      be downloaded.
    type: bool
    version_added: '2.4'
    version_added_collection: ansible.builtin

autoremove:
    default: 'no'
    description:
    - If C(yes), remove unused dependency packages for all module states except I(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.
    type: bool
    version_added: '2.1'
    version_added_collection: ansible.builtin

dpkg_options:
    default: force-confdef,force-confold
    description:
    - 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

only_upgrade:
    default: 'no'
    description:
    - Only upgrade a package if it is already installed.
    type: bool
    version_added: '2.1'
    version_added_collection: ansible.builtin

update_cache:
    default: 'no'
    description:
    - Run the equivalent of C(apt-get update) before the operation. Can be run as part
      of the package installation or as a separate step.
    type: bool

force_apt_get:
    default: 'no'
    description:
    - Force usage of apt-get instead of aptitude
    type: bool
    version_added: '2.4'
    version_added_collection: ansible.builtin

default_release:
    description:
    - Corresponds to the C(-t) option for I(apt) and sets pin priorities

cache_valid_time:
    default: 0
    description:
    - Update the apt cache if its older than the I(cache_valid_time). This option is set
      in seconds. As of Ansible 2.4, this implicitly sets I(update_cache) if set.

install_recommends:
    aliases:
    - install-recommends
    description:
    - Corresponds to the C(--no-install-recommends) option for I(apt). C(yes) installs
      recommended packages.  C(no) does not install recommended packages. By default,
      Ansible will use the same defaults as the operating system. Suggested packages are
      never installed.
    type: bool

allow_unauthenticated:
    default: 'no'
    description:
    - Ignore if packages cannot be authenticated. This is useful for bootstrapping environments
      that manage their own apt-key setup.
    type: bool
    version_added: '2.1'
    version_added_collection: ansible.builtin

Outputs

cache_update_time:
  description: time of the last cache update (0 if unknown)
  returned: success, in some cases
  sample: 1425828348000
  type: int
cache_updated:
  description: if the cache was updated or not
  returned: success, in some cases
  sample: true
  type: boolean
stderr:
  description: error output from apt
  returned: success, when needed
  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 ...'
  type: string
stdout:
  description: output from apt
  returned: success, when needed
  sample: 'Reading package lists... Building dependency tree... Reading state information...
    The following extra packages will be installed: apache2-bin ...'
  type: string