W3cubDocs

/Ansible 2.11

ansible.builtin.package – Generic OS package manager

Note

This module is part of ansible-base and included in all Ansible installations. In most cases, you can use the short module name package 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 2.0: of ansible.builtin

Synopsis

  • This modules manages packages on a target without specifying a package manager module (like ansible.builtin.yum, 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. package calls behind the module for the package manager used by the operating system discovered by the module ansible.builtin.setup. If setup was not yet run, 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 ansile.windows.win_package module instead.

Note

This module has a corresponding action plugin.

Requirements

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

  • Whatever is required for the package plugins specific for each system.

Parameters

Parameter Choices/Defaults Comments
name
string / required
Package name, or package specifier with version.
Syntax varies with package manager. For example name-1.0 or name=1.0.
Package names also vary with package manager; this module will not "translate" them per distro. For example libyaml-dev, libyaml-devel.
state
string / required
Whether to install (present), or remove (absent) a package.
You can use other states like latest ONLY if they are supported by the underlying package module(s) executed.
use
string
Default:
"auto"
The required package manager module to use (`yum`, `apt`, and so on). The default 'auto' will use existing facts or try to autodetect it.
You should only use this field if the automatic selection is not working for some reason.

Notes

Note

  • While 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

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.11/collections/ansible/builtin/package_module.html