iptables.yml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ---
  2. - name: Install iptables packages
  3. yum:
  4. name: "{{ item }}"
  5. state: present
  6. with_items:
  7. - iptables
  8. - iptables-services
  9. - name: Start and enable iptables services
  10. service:
  11. name: "{{ os_firewall_svc }}"
  12. state: started
  13. enabled: yes
  14. with_items:
  15. - iptables
  16. - ip6tables
  17. register: result
  18. - name: need to pause here, otherwise the iptables service starting can sometimes cause ssh to fail
  19. pause: seconds=10
  20. when: result | changed
  21. - name: Ensure firewalld service is not enabled
  22. service:
  23. name: firewalld
  24. state: stopped
  25. enabled: no
  26. - name: Mask firewalld service
  27. command: systemctl mask firewalld
  28. register: result
  29. failed_when: result.rc != 0
  30. changed_when: False
  31. ignore_errors: yes
  32. - name: Add iptables allow rules
  33. os_firewall_manage_iptables:
  34. name: "{{ item.service }}"
  35. action: add
  36. protocol: "{{ item.port.split('/')[1] }}"
  37. port: "{{ item.port.split('/')[0] }}"
  38. with_items: allow
  39. when: allow is defined
  40. - name: Remove iptables rules
  41. os_firewall_manage_iptables:
  42. name: "{{ item.service }}"
  43. action: remove
  44. protocol: "{{ item.port.split('/')[1] }}"
  45. port: "{{ item.port.split('/')[0] }}"
  46. with_items: deny
  47. when: deny is defined