Skip to content

Commit f632fad

Browse files
Merge pull request #598 from saito-hideki/issue/586
[Breaking Change] [firewalld] Change type of icmp_block_inversion option from str to bool SUMMARY Changed the type of icmp_block_inversion option from str to bool Fixes #586 ISSUE TYPE Bugfix Pull Request COMPONENT NAME ansible.posix.firewalld ADDITIONAL INFORMATION Related #582 and #584 Reviewed-by: Adam Miller <admiller@redhat.com> Reviewed-by: Andrew Klychkov <aklychko@redhat.com>
2 parents 74edb72 + 6175a50 commit f632fad

File tree

3 files changed

+33
-85
lines changed

3 files changed

+33
-85
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
breaking_changes:
3+
- firewalld - Changed the type of icmp_block_inversion option from str to bool (https://github.com/ansible-collections/ansible.posix/issues/586).

plugins/modules/firewalld.py

+30-28
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
icmp_block_inversion:
7575
description:
7676
- Enable/Disable inversion of ICMP blocks for a zone in firewalld.
77-
type: str
77+
- Note that the option type is changed to bool in ansible.posix version 2.0.0 and later.
78+
type: bool
7879
zone:
7980
description:
8081
- The firewalld zone to add/remove to/from.
@@ -152,89 +153,100 @@
152153
'''
153154

154155
EXAMPLES = r'''
155-
- name: permanently enable https service, also enable it immediately if possible
156+
- name: Permanently enable https service, also enable it immediately if possible
156157
ansible.posix.firewalld:
157158
service: https
158159
state: enabled
159160
permanent: true
160161
immediate: true
161162
offline: true
162163
163-
- name: permit traffic in default zone for https service
164+
- name: Permit traffic in default zone for https service
164165
ansible.posix.firewalld:
165166
service: https
166167
permanent: true
167168
state: enabled
168169
169-
- name: permit ospf traffic
170+
- name: Permit ospf traffic
170171
ansible.posix.firewalld:
171172
protocol: ospf
172173
permanent: true
173174
state: enabled
174175
175-
- name: do not permit traffic in default zone on port 8081/tcp
176+
- name: Do not permit traffic in default zone on port 8081/tcp
176177
ansible.posix.firewalld:
177178
port: 8081/tcp
178179
permanent: true
179180
state: disabled
180181
181-
- ansible.posix.firewalld:
182+
- name: Permit traffic in default zone on port 161-162/ucp
183+
ansible.posix.firewalld:
182184
port: 161-162/udp
183185
permanent: true
184186
state: enabled
185187
186-
- ansible.posix.firewalld:
188+
- name: Permit traffic in dmz zone on http service
189+
ansible.posix.firewalld:
187190
zone: dmz
188191
service: http
189192
permanent: true
190193
state: enabled
191194
192-
- ansible.posix.firewalld:
195+
- name: Enable FTP service with rate limiting using firewalld rich rule
196+
ansible.posix.firewalld:
193197
rich_rule: rule service name="ftp" audit limit value="1/m" accept
194198
permanent: true
195199
state: enabled
196200
197-
- ansible.posix.firewalld:
201+
- name: Allow traffic from 192.0.2.0/24 in internal zone
202+
ansible.posix.firewalld:
198203
source: 192.0.2.0/24
199204
zone: internal
200205
state: enabled
201206
202-
- ansible.posix.firewalld:
207+
- name: Assign eth2 interface to trusted zone
208+
ansible.posix.firewalld:
203209
zone: trusted
204210
interface: eth2
205211
permanent: true
206212
state: enabled
207213
208-
- ansible.posix.firewalld:
214+
- name: Enable forwarding in internal zone
215+
ansible.posix.firewalld:
209216
forward: true
210217
state: enabled
211218
permanent: true
212219
zone: internal
213220
214-
- ansible.posix.firewalld:
221+
- name: Enable masquerade in dmz zone
222+
ansible.posix.firewalld:
215223
masquerade: true
216224
state: enabled
217225
permanent: true
218226
zone: dmz
219227
220-
- ansible.posix.firewalld:
228+
- name: Create custom zone if not already present
229+
ansible.posix.firewalld:
221230
zone: custom
222231
state: present
223232
permanent: true
224233
225-
- ansible.posix.firewalld:
234+
- name: Enable ICMP block inversion in drop zone
235+
ansible.posix.firewalld:
226236
zone: drop
227237
state: enabled
228238
permanent: true
229239
icmp_block_inversion: true
230240
231-
- ansible.posix.firewalld:
241+
- name: Block ICMP echo requests in drop zone
242+
ansible.posix.firewalld:
232243
zone: drop
233244
state: enabled
234245
permanent: true
235246
icmp_block: echo-request
236247
237-
- ansible.posix.firewalld:
248+
- name: Set internal zone target to ACCEPT
249+
ansible.posix.firewalld:
238250
zone: internal
239251
state: present
240252
permanent: true
@@ -250,7 +262,6 @@
250262
'''
251263

252264
from ansible.module_utils.basic import AnsibleModule
253-
from ansible.module_utils.parsing.convert_bool import boolean
254265
from ansible_collections.ansible.posix.plugins.module_utils.firewalld import FirewallTransaction, fw_offline
255266

256267
try:
@@ -864,7 +875,7 @@ def main():
864875
module = AnsibleModule(
865876
argument_spec=dict(
866877
icmp_block=dict(type='str'),
867-
icmp_block_inversion=dict(type='str'),
878+
icmp_block_inversion=dict(type='bool'),
868879
service=dict(type='str'),
869880
protocol=dict(type='str'),
870881
port=dict(type='str'),
@@ -987,16 +998,7 @@ def main():
987998
msgs.append("Changed icmp-block %s to %s" % (icmp_block, desired_state))
988999

9891000
if icmp_block_inversion is not None:
990-
# Type of icmp_block_inversion will be changed to boolean in a future release.
991-
icmp_block_inversion_status = True
992-
try:
993-
icmp_block_inversion_status = boolean(icmp_block_inversion, True)
994-
except TypeError:
995-
module.warn('The value of the icmp_block_inversion option is "%s". '
996-
'The type of the option will be changed from string to boolean in a future release. '
997-
'To avoid unexpected behavior, please change the value to boolean.' % icmp_block_inversion)
998-
expected_state = 'enabled' if (desired_state == 'enabled') == icmp_block_inversion_status else 'disabled'
999-
1001+
expected_state = 'enabled' if (desired_state == 'enabled') == icmp_block_inversion else 'disabled'
10001002
transaction = IcmpBlockInversionTransaction(
10011003
module,
10021004
action_args=(),

tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml

-57
Original file line numberDiff line numberDiff line change
@@ -114,60 +114,3 @@
114114
ansible.builtin.assert:
115115
that:
116116
- result is not changed
117-
118-
# Validate backwards compatible behavior until icmp block inversion is switched from string to boolean type
119-
- name: Icmp block inversion enabled when icmp block inversion is non-boolean string and state is enabled
120-
block:
121-
- name: Testing enable icmp block inversion
122-
ansible.posix.firewalld:
123-
zone: trusted
124-
icmp_block_inversion: some string
125-
permanent: true
126-
state: enabled
127-
register: result
128-
129-
- name: Assert icmp block inversion is enabled
130-
ansible.builtin.assert:
131-
that:
132-
- result is changed
133-
134-
- name: Testing enable icmp block inversion (verify not changed)
135-
ansible.posix.firewalld:
136-
zone: trusted
137-
icmp_block_inversion: some string
138-
permanent: true
139-
state: enabled
140-
register: result
141-
142-
- name: Assert icmp block inversion is enabled (verify not changed)
143-
ansible.builtin.assert:
144-
that:
145-
- result is not changed
146-
147-
- name: Icmp block inversion disabled when icmp block inversion is non-boolean string and state is disabled
148-
block:
149-
- name: Testing disable icmp block inversion
150-
ansible.posix.firewalld:
151-
zone: trusted
152-
icmp_block_inversion: some string
153-
permanent: true
154-
state: disabled
155-
register: result
156-
157-
- name: Assert icmp block inversion is disabled
158-
ansible.builtin.assert:
159-
that:
160-
- result is changed
161-
162-
- name: Testing disable icmp block inversion (verify not changed)
163-
ansible.posix.firewalld:
164-
zone: trusted
165-
icmp_block_inversion: some string
166-
permanent: true
167-
state: disabled
168-
register: result
169-
170-
- name: Assert icmp block inversion is disabled (verify not changed)
171-
ansible.builtin.assert:
172-
that:
173-
- result is not changed

0 commit comments

Comments
 (0)