package_facts-module.yaml 975 B

123456789101112131415161718192021222324252627282930
  1. ---
  2. - name: "Gather the package facts ansible.builtin.package_facts"
  3. hosts: all
  4. gather_facts: True
  5. become: true
  6. tasks:
  7. - name: Gather the package facts
  8. package_facts:
  9. manager: auto
  10. - name: Print the package facts
  11. debug:
  12. var: ansible_facts.packages
  13. - name: Check whether a package called firewalld is installed
  14. ansible.builtin.debug:
  15. msg: "{{ ansible_facts.packages['firewalld'] | length }} versions of firewalld are installed!"
  16. when: "'firewalld' in ansible_facts.packages"
  17. - name: Check whether a package called aerhaewrhqwet is installed (True/false)
  18. ansible.builtin.debug:
  19. msg: "True"
  20. when: "'aerhaewrhqwet' in ansible_facts.packages"
  21. - name: Check whether a package called aerhaewrhqwet is installed (true/False)
  22. ansible.builtin.debug:
  23. msg: "False"
  24. when: "'aerhaewrhqwet' not in ansible_facts.packages"