1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- ---
- - name: Install iptables packages
- yum:
- name: "{{ item }}"
- state: present
- with_items:
- - iptables
- - iptables-services
- - name: Check if firewalld is installed
- command: rpm -q firewalld
- register: pkg_check
- failed_when: pkg_check.rc > 1
- changed_when: no
- - name: Ensure firewalld service is not enabled
- service:
- name: firewalld
- state: stopped
- enabled: no
- when: pkg_check.rc == 0
- - name: Start and enable iptables services
- service:
- name: "{{ item }}"
- state: started
- enabled: yes
- with_items:
- - iptables
- - ip6tables
- register: result
- - name: need to pause here, otherwise the iptables service starting can sometimes cause ssh to fail
- pause: seconds=10
- when: result | changed
- # TODO: submit PR upstream to add mask/unmask to service module
- - name: Mask firewalld service
- command: systemctl mask firewalld
- register: result
- changed_when: "'firewalld' in result.stdout"
- when: pkg_check.rc == 0
- # Workaround for Docker 1.4 to create DOCKER chain
- - name: Add DOCKER chain
- os_firewall_manage_iptables:
- name: "DOCKER chain"
- action: verify_chain
- create_jump_rule: no
- # End of Docker 1.4 workaround
- - name: Add iptables allow rules
- os_firewall_manage_iptables:
- name: "{{ item.service }}"
- action: add
- protocol: "{{ item.port.split('/')[1] }}"
- port: "{{ item.port.split('/')[0] }}"
- with_items: os_firewall_allow
- when: os_firewall_allow is defined
- - name: Remove iptables rules
- os_firewall_manage_iptables:
- name: "{{ item.service }}"
- action: remove
- protocol: "{{ item.port.split('/')[1] }}"
- port: "{{ item.port.split('/')[0] }}"
- with_items: os_firewall_deny
- when: os_firewall_deny is defined
|