I know I can use the package_facts module to retrieve a list of installed packages, but I'm having trouble formatting these. I'd like to format it similar to the following:
Package: <package> Version: <version>
Currently I'm doing the following (I'm showing only httpd but ultimately I'd like to list out ALL installed packages:
---
- hosts: localhost
become: true
become_method: sudo
gather_facts: no
tasks:
- name: Get installed packages
package_facts:
register: packages
- name: Debug output
debug:
msg: "{{ packages.ansible_facts.packages['httpd'] }}"
The debug print is giving me the following:
TASK [Debug output] ******************************************************************************************************************************
ok: [localhost] => {
"msg": [
{
"arch": "x86_64",
"epoch": null,
"name": "httpd",
"release": "97.el7_9",
"source": "rpm",
"version": "2.4.6"
}
]
}
Any ideas?
Thanks,
Harry