blob: 9af9d8d29e2f82909aec7909534f0c16fac49b13 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
---
- name: Install iptables packages
yum:
name: "{{ item }}"
state: present
with_items:
- iptables
- iptables-services
register: install_result
- 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: Reload systemd units
command: systemctl daemon-reload
when: install_result | changed
- name: Start and enable iptables service
service:
name: iptables
state: started
enabled: yes
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
ignore_errors: yes
- 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
|