firewalld.yml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ---
  2. - name: Install firewalld packages
  3. package: name=firewalld state=present
  4. when: not openshift.common.is_containerized | bool
  5. register: install_result
  6. - name: Check if iptables-services is installed
  7. command: rpm -q iptables-services
  8. register: pkg_check
  9. failed_when: pkg_check.rc > 1
  10. changed_when: no
  11. - name: Ensure iptables services are not enabled
  12. service:
  13. name: "{{ item }}"
  14. state: stopped
  15. enabled: no
  16. with_items:
  17. - iptables
  18. - ip6tables
  19. when: pkg_check.rc == 0
  20. - name: Reload systemd units
  21. command: systemctl daemon-reload
  22. when: install_result | changed
  23. - name: Determine if firewalld service masked
  24. command: >
  25. systemctl is-enabled firewalld
  26. register: os_firewall_firewalld_masked_output
  27. changed_when: false
  28. failed_when: false
  29. - name: Unmask firewalld service
  30. command: >
  31. systemctl unmask firewalld
  32. when: os_firewall_firewalld_masked_output.stdout == "masked"
  33. - name: Start and enable firewalld service
  34. service:
  35. name: firewalld
  36. state: started
  37. enabled: yes
  38. register: result
  39. - name: need to pause here, otherwise the firewalld service starting can sometimes cause ssh to fail
  40. pause: seconds=10
  41. when: result | changed
  42. - name: Mask iptables services
  43. command: systemctl mask "{{ item }}"
  44. register: result
  45. changed_when: "'iptables' in result.stdout"
  46. with_items:
  47. - iptables
  48. - ip6tables
  49. when: pkg_check.rc == 0
  50. ignore_errors: yes
  51. # TODO: Ansible 1.9 will eliminate the need for separate firewalld tasks for
  52. # enabling rules and making them permanent with the immediate flag
  53. - name: Add firewalld allow rules
  54. firewalld:
  55. port: "{{ item.port }}"
  56. permanent: false
  57. state: enabled
  58. with_items: "{{ os_firewall_allow }}"
  59. - name: Persist firewalld allow rules
  60. firewalld:
  61. port: "{{ item.port }}"
  62. permanent: true
  63. state: enabled
  64. with_items: "{{ os_firewall_allow }}"
  65. - name: Remove firewalld allow rules
  66. firewalld:
  67. port: "{{ item.port }}"
  68. permanent: false
  69. state: disabled
  70. with_items: "{{ os_firewall_deny }}"
  71. - name: Persist removal of firewalld allow rules
  72. firewalld:
  73. port: "{{ item.port }}"
  74. permanent: true
  75. state: disabled
  76. with_items: "{{ os_firewall_deny }}"