firewalld.yml 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ---
  2. - name: Install firewalld packages
  3. package:
  4. name: firewalld
  5. state: present
  6. - name: Ensure iptables services are not enabled
  7. systemd:
  8. name: "{{ item }}"
  9. state: stopped
  10. enabled: no
  11. masked: yes
  12. with_items:
  13. - iptables
  14. - ip6tables
  15. register: task_result
  16. failed_when: task_result|failed and 'could not' not in task_result.msg|lower
  17. - name: Wait 10 seconds after disabling iptables
  18. pause:
  19. seconds: 10
  20. when: task_result | changed
  21. - name: Start and enable firewalld service
  22. systemd:
  23. name: firewalld
  24. state: started
  25. enabled: yes
  26. masked: no
  27. daemon_reload: yes
  28. register: result
  29. - name: need to pause here, otherwise the firewalld service starting can sometimes cause ssh to fail
  30. pause: seconds=10
  31. when: result | changed
  32. - name: Restart polkitd
  33. systemd:
  34. name: polkit
  35. state: restarted
  36. when: result | changed
  37. # Fix suspected race between firewalld and polkit BZ1436964
  38. - name: Wait for polkit action to have been created
  39. command: pkaction --action-id=org.fedoraproject.FirewallD1.config.info
  40. ignore_errors: true
  41. register: pkaction
  42. changed_when: false
  43. until: pkaction.rc == 0
  44. retries: 6
  45. delay: 10
  46. - name: Add firewalld allow rules
  47. firewalld:
  48. port: "{{ item.port }}"
  49. permanent: true
  50. immediate: true
  51. state: enabled
  52. with_items: "{{ os_firewall_allow }}"
  53. - name: Remove firewalld allow rules
  54. firewalld:
  55. port: "{{ item.port }}"
  56. permanent: true
  57. immediate: true
  58. state: disabled
  59. with_items: "{{ os_firewall_deny }}"