ansible.builtin.apt (v2.4.4.0-1) — 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.4.4.0.post1

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: 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:
    - pkg
    - package
    default: null
    description:
    - A package name, 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.  Note that the apt-get commandline supports implicit regex matches
      here but we do not because it can let typos through easier (If you typo C(foo) as
      C(fo) apt-get would install packages that have "fo" in their name with a warning
      and a prompt for the user.  Since we don't have warnings and prompts before installing
      we disallow this.  Use an explicit fnmatch pattern if you want wildcarding)
    required: false

force:
    choices:
    - 'yes'
    - 'no'
    default: 'no'
    description:
    - If C(yes), force installs/removes.
    required: false

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

state:
    choices:
    - latest
    - absent
    - present
    - build-dep
    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.
    required: false

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

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

autoremove:
    choices:
    - 'yes'
    - 'no'
    default: false
    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.
    required: false
    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
    required: false

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

update_cache:
    choices:
    - 'yes'
    - 'no'
    default: false
    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.
    required: false

force_apt_get:
    default: false
    description:
    - Force usage of apt-get instead of aptitude
    required: false
    version_added: '2.4'
    version_added_collection: ansible.builtin

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

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.
    required: false

install_recommends:
    choices:
    - 'yes'
    - 'no'
    default: null
    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.
    required: false

allow_unauthenticated:
    choices:
    - 'yes'
    - 'no'
    default: 'no'
    description:
    - Ignore if packages cannot be authenticated. This is useful for bootstrapping environments
      that manage their own apt-key setup.
    required: false
    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