14
14
short_description: Manage firewall rules in Proxmox
15
15
version_added: "1.4.0"
16
16
description:
17
- - create/update/delete FW rules at cluster/group/vnet/node/vm level
18
- - Create/delete firewall security groups
19
- - get firewall rules at cluster/group/vnet/node/vm level
17
+ - Create/update/delete firewall rules at cluster/group/vnet/node/vm level.
18
+ - Create/delete firewall security groups.
20
19
author: 'Jana Hoch <[email protected] > (!UNKNOWN)'
21
20
attributes:
22
21
check_mode:
26
25
options:
27
26
state:
28
27
description:
29
- - create/update/delete firewall rules or security group
30
- - if state is not provided then it will just list firewall rules at level
28
+ - Create/update/delete firewall rules or security group.
31
29
type: str
32
30
choices:
33
31
- present
34
32
- absent
35
33
default: present
36
34
update:
37
35
description:
38
- - If O(state=present) and if 1 or more rule/alias already exists it will update them
36
+ - If O(state=present) and if one or more rule/alias already exists it will update them.
39
37
type: bool
40
38
default: true
41
39
level:
52
50
node:
53
51
description:
54
52
- Name of the node.
55
- - only needed when level is node.
53
+ - Only needed when O( level= node) .
56
54
type: str
57
55
vmid:
58
56
description:
59
57
- ID of the VM to which the rule applies.
60
- - only needed when level is vm .
58
+ - Only needed when O( level=vm) .
61
59
type: int
62
60
vnet:
63
61
description:
64
62
- Name of the virtual network for the rule.
65
- - only needed when level is vnet.
63
+ - Only needed when O( level= vnet) .
66
64
type: str
67
65
pos:
68
66
description:
69
67
- Position of the rule in the list.
70
- - only needed if deleting rule or trying to list it
68
+ - Only needed if O(state=absent).
71
69
type: int
72
70
group_conf:
73
71
description:
77
75
group:
78
76
description:
79
77
- Name of the group to which the rule belongs.
80
- - only needed when level is group or group_conf is True .
78
+ - Only needed when O( level= group) or O( group_conf=true) .
81
79
type: str
82
80
comment:
83
81
description:
86
84
type: str
87
85
aliases:
88
86
description:
89
- - List of aliases
90
- - Alias can only be created/updated/deleted at cluster or VM level
87
+ - List of aliases.
88
+ - Alias can only be created/updated/deleted at cluster or VM level.
91
89
type: list
92
90
elements: dict
93
91
suboptions:
94
92
name:
95
- description: Alias name
93
+ description: Alias name.
96
94
type: str
97
95
required: true
98
96
cidr:
99
97
description:
100
- - CIDR for alias
101
- - only needed when O(state=present) or O(state=update)
98
+ - CIDR for alias.
99
+ - Only needed when O(state=present) or O(state=update).
102
100
type: str
103
101
required: false
104
102
comment:
105
- description: Comment for Alias
103
+ description: Comment for alias.
106
104
type: str
107
105
required: false
108
106
rules:
215
213
api_token_id: "{{ pc.proxmox.api_token_id }}"
216
214
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
217
215
api_host: "{{ pc.proxmox.api_host }}"
218
- validate_certs: no
216
+ validate_certs: false
219
217
level: cluster
220
218
state: present
221
219
rules:
224
222
source: 1.1.1.1
225
223
log: nolog
226
224
pos: 9
227
- enable: True
225
+ enable: true
228
226
- type: out
229
227
action: ACCEPT
230
228
source: 1.0.0.1
231
229
pos: 10
232
- enable: True
230
+ enable: true
233
231
234
232
- name: Update Cluster level firewall rules
235
233
community.proxmox.proxmox_firewall:
236
234
api_user: "{{ pc.proxmox.api_user }}"
237
235
api_token_id: "{{ pc.proxmox.api_token_id }}"
238
236
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
239
237
api_host: "{{ pc.proxmox.api_host }}"
240
- validate_certs: no
238
+ validate_certs: false
241
239
level: cluster
242
240
state: present
243
- update: True
241
+ update: true
244
242
rules:
245
243
- type: out
246
244
action: ACCEPT
247
245
source: 8.8.8.8
248
246
log: nolog
249
247
pos: 9
250
- enable: False
248
+ enable: false
251
249
- type: out
252
250
action: ACCEPT
253
251
source: 8.8.4.4
254
252
pos: 10
255
- enable: False
253
+ enable: false
256
254
257
255
- name: Delete cluster level firewall rule at pos 10
258
256
community.proxmox.proxmox_firewall:
259
257
api_user: "{{ pc.proxmox.api_user }}"
260
258
api_token_id: "{{ pc.proxmox.api_token_id }}"
261
259
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
262
260
api_host: "{{ pc.proxmox.api_host }}"
263
- validate_certs: no
261
+ validate_certs: false
264
262
level: cluster
265
263
state: absent
266
264
pos: 10
271
269
api_token_id: "{{ pc.proxmox.api_token_id }}"
272
270
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
273
271
api_host: "{{ pc.proxmox.api_host }}"
274
- validate_certs: no
275
- group_conf: True
272
+ validate_certs: false
273
+ group_conf: true
276
274
state: present
277
275
group: test
278
276
282
280
api_token_id: "{{ pc.proxmox.api_token_id }}"
283
281
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
284
282
api_host: "{{ pc.proxmox.api_host }}"
285
- validate_certs: no
286
- group_conf: True
283
+ validate_certs: false
284
+ group_conf: true
287
285
state: absent
288
286
group: test
289
287
293
291
api_token_id: "{{ pc.proxmox.api_token_id }}"
294
292
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
295
293
api_host: "{{ pc.proxmox.api_host }}"
296
- validate_certs: no
294
+ validate_certs: false
297
295
state: present
298
296
aliases:
299
297
- name: test1
307
305
api_token_id: "{{ pc.proxmox.api_token_id }}"
308
306
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
309
307
api_host: "{{ pc.proxmox.api_host }}"
310
- validate_certs: no
308
+ validate_certs: false
311
309
state: present
312
- update: True
310
+ update: true
313
311
aliases:
314
312
- name: test1
315
313
cidr: '10.10.1.0/28'
322
320
api_token_id: "{{ pc.proxmox.api_token_id }}"
323
321
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
324
322
api_host: "{{ pc.proxmox.api_host }}"
325
- validate_certs: no
323
+ validate_certs: false
326
324
state: absent
327
325
aliases:
328
326
- name: test1
@@ -433,7 +431,7 @@ def validate_params(self):
433
431
return True
434
432
else :
435
433
self .module .fail_json (
436
- msg = "When State is absent either group_conf should be true or pos/aliases must be present but not both"
434
+ msg = "When state is absent either group_conf should be true or pos/aliases must be present but not both"
437
435
)
438
436
439
437
def run (self ):
@@ -447,7 +445,7 @@ def run(self):
447
445
group = self .params .get ("group" )
448
446
group_conf = self .params .get ("group_conf" )
449
447
450
- if rules is not None :
448
+ if rules :
451
449
for rule in rules :
452
450
rule ['icmp-type' ] = rule .get ('icmp_type' )
453
451
rule ['enable' ] = ansible_to_proxmox_bool (rule .get ('enable' ))
@@ -479,20 +477,20 @@ def run(self):
479
477
if state == "present" :
480
478
if group_conf :
481
479
self .group_present (group = group , comment = self .params .get ('comment' ))
482
- if rules is not None :
480
+ if rules :
483
481
self .fw_rules_present (rules_obj = rules_obj , rules = rules , update = update )
484
- if aliases is not None :
482
+ if aliases :
485
483
self .aliases_present (firewall_obj = firewall_obj , level = level , aliases = aliases , update = update )
486
484
elif state == "absent" :
487
485
if self .params .get ('pos' ):
488
486
self .fw_rule_absent (rules_obj = rules_obj , pos = self .params .get ('pos' ))
489
487
if group_conf :
490
488
self .group_absent (group_name = group )
491
- if aliases is not None :
489
+ if aliases :
492
490
self .aliases_absent (firewall_obj = firewall_obj , aliases = aliases )
493
491
494
492
def aliases_present (self , firewall_obj , level , aliases , update ):
495
- if firewall_obj is None or level not in ['cluster' , 'vm' ]:
493
+ if not firewall_obj or level not in ['cluster' , 'vm' ]:
496
494
self .module .fail_json (
497
495
msg = 'Aliases can only be created at cluster or VM level'
498
496
)
0 commit comments