I am trying to list all installed packages on my Debian 7 (Wheezy), 8 (Jessie), and 9 (Stretch) machines. There are easy ways dealing with it using APT or dpkg
, but I could not find a proper way to do this with Ansible out of the box.
Is there a nice and smooth way to do this?
For RHEL machines I found this post: How can I get the installed YUM packages with Ansible?
Since Ansible 2.5 you can use the package_facts module: ansible.builtin.package_facts module – Package information as facts
- name: Gather package facts
package_facts:
manager: auto
- name: Debug if package is present
debug:
msg: 'yes, mypackage is present'
when: '"mypackage" in ansible_facts.packages'
- name: Debug if package is absent
debug:
msg: 'no, mypackage is absent'
when: '"mypackage" not in ansible_facts.packages'
Mind you, you need the ansible-apt module on Debian for that (which is kindly provided by bootstrap).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With