firewalld.yml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ---
  2. - name: Install firewalld packages
  3. yum:
  4. name: firewalld
  5. state: present
  6. - name: Start and enable firewalld service
  7. service:
  8. name: firewalld
  9. state: started
  10. enabled: yes
  11. register: result
  12. - name: need to pause here, otherwise the firewalld service starting can sometimes cause ssh to fail
  13. pause: seconds=10
  14. when: result | changed
  15. - name: Ensure iptables services are not enabled
  16. service:
  17. name: "{{ item }}"
  18. state: stopped
  19. enabled: no
  20. with_items:
  21. - iptables
  22. - ip6tables
  23. - name: Mask iptables services
  24. command: systemctl mask "{{ item }}"
  25. register: result
  26. failed_when: result.rc != 0
  27. changed_when: False
  28. with_items:
  29. - iptables
  30. - ip6tables
  31. # TODO: Ansible 1.9 will eliminate the need for separate firewalld tasks for
  32. # enabling rules and making them permanent with the immediate flag
  33. - name: Add firewalld allow rules
  34. firewalld:
  35. port: "{{ item.port }}"
  36. permanent: false
  37. state: enabled
  38. with_items: allow
  39. when: allow is defined
  40. - name: Persist firewalld allow rules
  41. firewalld:
  42. port: "{{ item.port }}"
  43. permanent: true
  44. state: enabled
  45. with_items: allow
  46. when: allow is defined
  47. - name: Remove firewalld allow rules
  48. firewalld:
  49. port: "{{ item.port }}"
  50. permanent: false
  51. state: disabled
  52. with_items: deny
  53. when: deny is defined
  54. - name: Persist removal of firewalld allow rules
  55. firewalld:
  56. port: "{{ item.port }}"
  57. permanent: true
  58. state: disabled
  59. with_items: deny
  60. when: deny is defined