Skip to content

Commit fc643b7

Browse files
committed
feat: support includes for services
Feature: Allow for includes to be specified for services. Includes are described at https://firewalld.org/documentation/man-pages/firewalld.service.html Reason: This makes firewalld services more explicit and easier / quicker to read when there are many non-standard ports. Result: Users can specify other services to include when creating and setting services. Signed-off-by: Rich Megginson <[email protected]> Fixes #255
1 parent 26af17f commit fc643b7

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,19 @@ helper_module: ftp
698698
helper_module: nf_conntrack_ftp
699699
```
700700

701+
### includes
702+
703+
Name of one or more services to specify in an `include` in a
704+
service definition. The `include` directive is described in the
705+
[service manpage](https://firewalld.org/documentation/man-pages/firewalld.service.html)
706+
This can only be used when managing service definitions.
707+
708+
```yaml
709+
includes:
710+
- https
711+
- ldaps
712+
```
713+
701714
### timeout
702715

703716
The amount of time in seconds a setting is in effect. The timeout is usable if

library/firewall_lib.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@
250250
type: list
251251
elements: str
252252
default: []
253+
includes:
254+
description:
255+
Services to include in this one.
256+
required: false
257+
type: list
258+
elements: str
259+
default: []
253260
__report_changed:
254261
description:
255262
If false, do not report changed true even if changed.
@@ -691,6 +698,7 @@ def main():
691698
protocol=dict(required=False, type="list", elements="str", default=[]),
692699
helper_module=dict(required=False, type="list", elements="str", default=[]),
693700
destination=dict(required=False, type="list", elements="str", default=[]),
701+
includes=dict(required=False, type="list", elements="str", default=[]),
694702
__report_changed=dict(required=False, type="bool", default=True),
695703
),
696704
supports_check_mode=True,
@@ -771,6 +779,7 @@ def main():
771779
permanent = module.params["permanent"]
772780
runtime = module.params["runtime"]
773781
state = module.params["state"]
782+
includes = module.params["includes"]
774783

775784
# All options that require state to be set
776785
state_required = any(
@@ -1146,6 +1155,11 @@ def exception_handler(exception_message):
11461155
if not module.check_mode:
11471156
fw_service_settings.setDestination("ipv6", destination_ipv6)
11481157
changed = True
1158+
for _include in includes:
1159+
if not fw_service_settings.queryInclude(_include):
1160+
if not module.check_mode:
1161+
fw_service_settings.addInclude(_include)
1162+
changed = True
11491163
if state == "absent" and service_exists:
11501164
if port:
11511165
for _port, _protocol in port:
@@ -1181,6 +1195,11 @@ def exception_handler(exception_message):
11811195
if not module.check_mode:
11821196
fw_service_settings.removeDestination("ipv6", destination_ipv6)
11831197
changed = True
1198+
for _include in includes:
1199+
if fw_service_settings.queryInclude(_include):
1200+
if not module.check_mode:
1201+
fw_service_settings.removeInclude(_include)
1202+
changed = True
11841203
if not any(
11851204
(
11861205
port,

tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
permanent: "{{ item.permanent | default(True) }}"
112112
runtime: "{{ item.runtime | default(True) }}"
113113
state: "{{ item.state | default(omit) }}"
114+
includes: "{{ item.includes | default(omit) }}"
114115
__report_changed: "{{ __firewall_report_changed }}"
115116
loop: "{{ firewall is mapping | ternary([firewall], firewall) |
116117
map('dict2items') | map('difference', __previous) |

tests/tests_ansible.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,28 @@
536536
register: result
537537
failed_when: result is failed or result is not changed
538538

539+
- name: Add includes
540+
firewall_lib:
541+
service: customservice
542+
includes:
543+
- https
544+
- ldaps
545+
state: present
546+
permanent: true
547+
register: result
548+
failed_when: result is failed or result is not changed
549+
550+
- name: Add includes again to check idempotence
551+
firewall_lib:
552+
service: customservice
553+
includes:
554+
- https
555+
- ldaps
556+
state: present
557+
permanent: true
558+
register: result
559+
failed_when: result is failed or result is changed
560+
539561
- name: Delete custom service
540562
firewall_lib:
541563
service: customservice
@@ -564,6 +586,9 @@
564586
destination:
565587
- 123.45.6.78
566588
- "aaaa:aaaa:aaaa:aaa:aaaa:aaaa:aaaa::"
589+
includes:
590+
- https
591+
- ldaps
567592
permanent: true
568593
state: present
569594
register: result

tests/tests_service.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
destination:
7070
- 1.1.1.1
7171
- 1::1
72+
includes:
73+
- ssh
74+
- ldaps
7275
permanent: true
7376
state: present
7477

@@ -88,6 +91,9 @@
8891
destination:
8992
- 1.1.1.1
9093
- 1::1
94+
includes:
95+
- ssh
96+
- ldaps
9197
permanent: true
9298
state: present
9399

@@ -118,6 +124,9 @@
118124
- 1::1
119125
helper_module: ftp
120126
protocol: icmp
127+
includes:
128+
- ssh
129+
- ldaps
121130
permanent: true
122131
state: present
123132

@@ -158,6 +167,9 @@
158167
- 1::1
159168
helper_module: ftp
160169
protocol: icmp
170+
includes:
171+
- ssh
172+
- ldaps
161173
permanent: true
162174
state: present
163175

@@ -233,6 +245,9 @@
233245
- 1::1
234246
helper_module: ftp
235247
protocol: icmp
248+
includes:
249+
- ssh
250+
- ldaps
236251
permanent: true
237252
state: absent
238253

@@ -256,6 +271,9 @@
256271
- 1::1
257272
helper_module: ftp
258273
protocol: icmp
274+
includes:
275+
- ssh
276+
- ldaps
259277
permanent: true
260278
state: absent
261279

0 commit comments

Comments
 (0)