ansible.builtin.package_facts – Package information as facts
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_facts 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.5: of ansible.builtin
Synopsis
- Return information about installed packages as facts.
Requirements
The below requirements are needed on the host that executes this module.
- For ‘portage’ support it requires the
qlist
utility, which is part of ‘app-portage/portage-utils’. - For Debian-based systems
python-apt
package must be installed on targeted hosts.
Parameters
Parameter | Choices/Defaults | Comments |
---|---|---|
manager list / elements=string |
["auto"] | The package manager used by the system so we can query the package information. Since 2.8 this is a list and can support multiple package managers per system. The 'portage' and 'pkg' options were added in version 2.8. The 'apk' option was added in version 2.11. |
strategy string added in 2.8 of ansible.builtin |
| This option controls how the module queries the package managers on the system. first means it will return only information for the first supported package manager available. all will return information for all supported and available package managers on the system. |
Notes
Note
- Supports
check_mode
.
Examples
- name: Gather the package facts ansible.builtin.package_facts: manager: auto - name: Print the package facts ansible.builtin.debug: var: ansible_facts.packages - name: Check whether a package called foobar is installed ansible.builtin.debug: msg: "{{ ansible_facts.packages['foobar'] | length }} versions of foobar are installed!" when: "'foobar' in ansible_facts.packages"
Returned Facts
Facts returned by this module are added/updated in the hostvars
host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.
Fact | Returned | Description | |
---|---|---|---|
packages dictionary / elements=string | when operating system level package manager is specified or auto detected manager | Maps the package name to a non-empty list of dicts with package information. Every dict in the list corresponds to one installed version of the package. The fields described below are present for all package managers. Depending on the package manager, there might be more fields for a package. Sample: { "packages": { "kernel": [ { "name": "kernel", "source": "rpm", "version": "3.10.0", ... }, { "name": "kernel", "source": "rpm", "version": "3.10.0", ... }, ... ], "kernel-tools": [ { "name": "kernel-tools", "source": "rpm", "version": "3.10.0", ... } ], ... } } # Sample rpm { "packages": { "kernel": [ { "arch": "x86_64", "epoch": null, "name": "kernel", "release": "514.26.2.el7", "source": "rpm", "version": "3.10.0" }, { "arch": "x86_64", "epoch": null, "name": "kernel", "release": "514.16.1.el7", "source": "rpm", "version": "3.10.0" }, { "arch": "x86_64", "epoch": null, "name": "kernel", "release": "514.10.2.el7", "source": "rpm", "version": "3.10.0" }, { "arch": "x86_64", "epoch": null, "name": "kernel", "release": "514.21.1.el7", "source": "rpm", "version": "3.10.0" }, { "arch": "x86_64", "epoch": null, "name": "kernel", "release": "693.2.2.el7", "source": "rpm", "version": "3.10.0" } ], "kernel-tools": [ { "arch": "x86_64", "epoch": null, "name": "kernel-tools", "release": "693.2.2.el7", "source": "rpm", "version": "3.10.0" } ], "kernel-tools-libs": [ { "arch": "x86_64", "epoch": null, "name": "kernel-tools-libs", "release": "693.2.2.el7", "source": "rpm", "version": "3.10.0" } ], } } # Sample deb { "packages": { "libbz2-1.0": [ { "version": "1.0.6-5", "source": "apt", "arch": "amd64", "name": "libbz2-1.0" } ], "patch": [ { "version": "2.7.1-4ubuntu1", "source": "apt", "arch": "amd64", "name": "patch" } ], } } | |
name string / elements=string | always | The package's name. | |
source string / elements=string | always | Where information on the package came from. | |
version string / elements=string | always | The package's version. |
Authors
- Matthew Jones (@matburt)
- Brian Coca (@bcoca)
- Adam Miller (@maxamillion)
© 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_facts_module.html