determine_firewall.yaml 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ---
  2. - name: "Update firewall rules for Zabbix agent"
  3. hosts: all
  4. gather_facts: True
  5. become: true
  6. tasks:
  7. - name: Gather package facts
  8. package_facts:
  9. manager: auto
  10. - name: Populate systemd service_facts
  11. service_facts:
  12. #
  13. #################################
  14. # Determine and set the firewall method
  15. - name: Set variable to indicate which firewall method is being used by a systemd
  16. set_fact:
  17. FW_METHOD: "ufw"
  18. when: "'ufw' in ansible_facts.packages"
  19. - name: Set variable to indicate which firewall method is being used by a systemd
  20. set_fact:
  21. FW_METHOD: "iptables"
  22. when: "'iptables' in ansible_facts.packages"
  23. - name: Set variable to indicate which firewall method is being used by a systemd
  24. set_fact:
  25. FW_METHOD: "firewalld"
  26. when:
  27. - ansible_facts.distribution_file_variety != "Debian"
  28. - ansible_facts.services['firewalld.service']['status'] == 'enabled' or ansible_facts.services['firewalld.service']['status'] == 'running'
  29. - name: Set variable to indicate which firewall method is being used by a systemd
  30. set_fact:
  31. FW_METHOD: "firewalld"
  32. when:
  33. - ansible_facts.distribution_file_variety != "Debian"
  34. - ansible_facts.services['iptables.service']['status'] == 'enabled' or ansible_facts.services['iptables.service']['status'] == 'running'
  35. - name: Show value of FW_METHOD
  36. debug:
  37. msg: FW_METHOD is "{{ FW_METHOD }}"