ansible.builtin.package_facts module – Package information as facts
Note
This module is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
module name
package_facts
even without specifying the collections keyword.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.package_facts
for easy linking to the
module documentation and to avoid conflicting with other collections that may have
the same module name.
Synopsis
Return information about installed packages as facts.
Requirements
The below requirements are needed on the host that executes this module.
See details per package manager in the
manager
option.
Parameters
Parameter |
Comments |
---|---|
The package manager(s) used by the system so we can query the package information. This is a list and can support multiple package managers per system, since version 2.8. The The The Aliases were added in 2.18, to support using Choices:
Default: |
|
This option controls how the module queries the package managers on the system. Choices:
|
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in check_mode and return changed status prediction without modifying target, if not supported the action will be skipped. |
|
Support: none |
Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode |
|
Support: full |
Action returns an |
|
Platform: posix |
Target OS/families that can be operated against |
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.
Key |
Description |
---|---|
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. Returned: when operating system level package manager is specified or auto detected manager Sample: |
|
The package’s name. Returned: always |
|
Where information on the package came from. Returned: always |
|
The package’s version. Returned: always |