Skip to content

package

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 2.0.

You need further requirements to be able to use this module, see the Requirements section for details.

Synopsis

  • This modules manages packages on a target without specifying a package manager module (like M(ansible.builtin.dnf), M(ansible.builtin.apt), ...). It is convenient to use in an heterogeneous environment of machines without having to create a specific task for each package manager. M(ansible.builtin.package) calls behind the module for the package manager used by the operating system discovered by the module M(ansible.builtin.setup). If M(ansible.builtin.setup) was not yet run, M(ansible.builtin.package) will run it.
  • This module acts as a proxy to the underlying package manager module. While all arguments will be passed to the underlying module, not all modules support the same arguments. This documentation only covers the minimum intersection of module arguments that all packaging modules support.
  • For Windows targets, use the M(ansible.windows.win_package) module instead.

Requirements

The following Python packages are needed on the host that executes this module:

Parameters

Parameter Defaults / Choices Comments
name
required
Package name, or package specifier with version.
Syntax varies with package manager. For example V(name-1.0) or V(name=1.0).
Package names also vary with package manager; this module will not "translate" them per distribution. For example V(libyaml-dev), V(libyaml-devel).
To operate on several packages this can accept a comma separated string of packages or a list of packages, depending on the underlying package manager.
state
required
Whether to install (V(present)), or remove (V(absent)) a package.
You can use other states like V(latest) ONLY if they are supported by the underlying package module(s) executed.
use Default: auto
The required package manager module to use (V(dnf), V(apt), and so on). The default V(auto) will use existing facts or try to auto-detect it.
You should only use this field if the automatic selection is not working for some reason.
Since version 2.17 you can use the C(ansible_package_use) variable to override the automatic detection, but this option still takes precedence.

Notes

Note

  • While M(ansible.builtin.package) abstracts package managers to ease dealing with multiple distributions, package name often differs for the same software.

Examples

- name: Install ntpdate
  ansible.builtin.package:
    name: ntpdate
    state: present

# This uses a variable as this changes per distribution.
- name: Remove the apache package
  ansible.builtin.package:
    name: "{{ apache }}"
    state: absent

- name: Install the latest version of Apache and MariaDB
  ansible.builtin.package:
    name:
      - httpd
      - mariadb-server
    state: latest

Authors

  • Ansible Core Team