49
49
cidrs:
50
50
description:
51
51
- List of CIDRs (full notation) to be used for firewall rule.
52
- - Since version 2.5, it is a list of CIDR.
53
52
elements: str
54
53
type: list
55
54
default: 0.0.0.0/0
56
55
aliases: [ cidr ]
56
+ dest_cidrs:
57
+ description:
58
+ - List of destination CIDRs (full notation) to forward traffic to if I(type=egress).
59
+ elements: str
60
+ type: list
61
+ aliases: [ dest_cidr ]
62
+ version_added: 2.2.0
57
63
start_port:
58
64
description:
59
65
- Start port for this rule.
178
184
returned: success
179
185
type: list
180
186
sample: [ '0.0.0.0/0' ]
187
+ dest_cidrs:
188
+ description: CIDR list of the rule to forward traffic to.
189
+ returned: success
190
+ type: list
191
+ sample: [ '0.0.0.0/0' ]
192
+ version_added: 2.2.0
181
193
protocol:
182
194
description: Protocol of the rule.
183
195
returned: success
@@ -224,6 +236,7 @@ def __init__(self, module):
224
236
super (AnsibleCloudStackFirewall , self ).__init__ (module )
225
237
self .returns = {
226
238
'cidrlist' : 'cidr' ,
239
+ 'destcidrlist' : 'dest_cidrs' ,
227
240
'startport' : 'start_port' ,
228
241
'endport' : 'end_port' ,
229
242
'protocol' : 'protocol' ,
@@ -237,6 +250,7 @@ def __init__(self, module):
237
250
def get_firewall_rule (self ):
238
251
if not self .firewall_rule :
239
252
cidrs = self .module .params .get ('cidrs' )
253
+ dest_cidrs = self .module .params .get ('destcidrs' )
240
254
protocol = self .module .params .get ('protocol' )
241
255
start_port = self .module .params .get ('start_port' )
242
256
end_port = self .get_or_fallback ('end_port' , 'start_port' )
@@ -280,7 +294,7 @@ def get_firewall_rule(self):
280
294
281
295
if firewall_rules :
282
296
for rule in firewall_rules :
283
- type_match = self ._type_cidrs_match (rule , cidrs , egress_cidrs )
297
+ type_match = self ._type_cidrs_match (rule , cidrs , egress_cidrs ) and self . _type_dest_cidrs_match ( rule , dest_cidrs )
284
298
285
299
protocol_match = (
286
300
self ._tcp_udp_match (rule , protocol , start_port , end_port ) or
@@ -322,13 +336,18 @@ def _type_cidrs_match(self, rule, cidrs, egress_cidrs):
322
336
else :
323
337
return "," .join (cidrs ) == rule ['cidrlist' ]
324
338
339
+ def _type_dest_cidrs_match (self , rule , dest_cidrs ):
340
+ if dest_cidrs is not None and 'destcidrlist' in rule :
341
+ return "," .join (dest_cidrs ) == rule ['destcidrlist' ]
342
+
325
343
def create_firewall_rule (self ):
326
344
firewall_rule = self .get_firewall_rule ()
327
345
if not firewall_rule :
328
346
self .result ['changed' ] = True
329
347
330
348
args = {
331
349
'cidrlist' : self .module .params .get ('cidrs' ),
350
+ 'destcidrlist' : self .module .params .get ('dest_cidrs' ),
332
351
'protocol' : self .module .params .get ('protocol' ),
333
352
'startport' : self .module .params .get ('start_port' ),
334
353
'endport' : self .get_or_fallback ('end_port' , 'start_port' ),
@@ -393,6 +412,7 @@ def main():
393
412
ip_address = dict (),
394
413
network = dict (),
395
414
cidrs = dict (type = 'list' , elements = 'str' , default = '0.0.0.0/0' , aliases = ['cidr' ]),
415
+ dest_cidrs = dict (type = 'list' , elements = 'str' , aliases = ['dest_cidr' ]),
396
416
protocol = dict (choices = ['tcp' , 'udp' , 'icmp' , 'all' ], default = 'tcp' ),
397
417
type = dict (choices = ['ingress' , 'egress' ], default = 'ingress' ),
398
418
icmp_type = dict (type = 'int' ),
0 commit comments