iptables.yml 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ---
  2. - name: Ensure firewalld service is not enabled
  3. systemd:
  4. name: firewalld
  5. state: stopped
  6. enabled: no
  7. masked: yes
  8. register: task_result
  9. failed_when: "task_result|failed and 'could not' not in task_result.msg|lower"
  10. - name: Install iptables packages
  11. package: name={{ item }} state=present
  12. with_items:
  13. - iptables
  14. - iptables-services
  15. when: not openshift.common.is_atomic | bool
  16. - name: Start and enable iptables service
  17. systemd:
  18. name: iptables
  19. state: started
  20. enabled: yes
  21. masked: no
  22. daemon_reload: yes
  23. register: result
  24. - name: need to pause here, otherwise the iptables service starting can sometimes cause ssh to fail
  25. pause: seconds=10
  26. when: result | changed
  27. - name: Add iptables allow rules
  28. os_firewall_manage_iptables:
  29. name: "{{ item.service }}"
  30. action: add
  31. protocol: "{{ item.port.split('/')[1] }}"
  32. port: "{{ item.port.split('/')[0] }}"
  33. with_items: "{{ os_firewall_allow }}"
  34. - name: Remove iptables rules
  35. os_firewall_manage_iptables:
  36. name: "{{ item.service }}"
  37. action: remove
  38. protocol: "{{ item.port.split('/')[1] }}"
  39. port: "{{ item.port.split('/')[0] }}"
  40. with_items: "{{ os_firewall_deny }}"