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' ]
181
192
protocol:
182
193
description: Protocol of the rule.
183
194
returned: success
@@ -224,6 +235,7 @@ def __init__(self, module):
224
235
super (AnsibleCloudStackFirewall , self ).__init__ (module )
225
236
self .returns = {
226
237
'cidrlist' : 'cidr' ,
238
+ 'destcidrlist' : 'dest_cidrs' ,
227
239
'startport' : 'start_port' ,
228
240
'endport' : 'end_port' ,
229
241
'protocol' : 'protocol' ,
@@ -237,6 +249,7 @@ def __init__(self, module):
237
249
def get_firewall_rule (self ):
238
250
if not self .firewall_rule :
239
251
cidrs = self .module .params .get ('cidrs' )
252
+ dest_cidrs = self .module .params .get ('destcidrs' )
240
253
protocol = self .module .params .get ('protocol' )
241
254
start_port = self .module .params .get ('start_port' )
242
255
end_port = self .get_or_fallback ('end_port' , 'start_port' )
@@ -280,7 +293,7 @@ def get_firewall_rule(self):
280
293
281
294
if firewall_rules :
282
295
for rule in firewall_rules :
283
- type_match = self ._type_cidrs_match (rule , cidrs , egress_cidrs )
296
+ type_match = self ._type_cidrs_match (rule , cidrs , egress_cidrs ) and self . _type_dest_cidrs_match ( rule , dest_cidrs )
284
297
285
298
protocol_match = (
286
299
self ._tcp_udp_match (rule , protocol , start_port , end_port ) or
@@ -322,13 +335,18 @@ def _type_cidrs_match(self, rule, cidrs, egress_cidrs):
322
335
else :
323
336
return "," .join (cidrs ) == rule ['cidrlist' ]
324
337
338
+ def _type_dest_cidrs_match (self , rule , dest_cidrs ):
339
+ if dest_cidrs is not None and 'destcidrlist' in rule :
340
+ return "," .join (dest_cidrs ) == rule ['destcidrlist' ]
341
+
325
342
def create_firewall_rule (self ):
326
343
firewall_rule = self .get_firewall_rule ()
327
344
if not firewall_rule :
328
345
self .result ['changed' ] = True
329
346
330
347
args = {
331
348
'cidrlist' : self .module .params .get ('cidrs' ),
349
+ 'destcidrlist' : self .module .params .get ('dest_cidrs' ),
332
350
'protocol' : self .module .params .get ('protocol' ),
333
351
'startport' : self .module .params .get ('start_port' ),
334
352
'endport' : self .get_or_fallback ('end_port' , 'start_port' ),
@@ -393,6 +411,7 @@ def main():
393
411
ip_address = dict (),
394
412
network = dict (),
395
413
cidrs = dict (type = 'list' , elements = 'str' , default = '0.0.0.0/0' , aliases = ['cidr' ]),
414
+ dest_cidrs = dict (type = 'list' , elements = 'str' , aliases = ['dest_cidr' ]),
396
415
protocol = dict (choices = ['tcp' , 'udp' , 'icmp' , 'all' ], default = 'tcp' ),
397
416
type = dict (choices = ['ingress' , 'egress' ], default = 'ingress' ),
398
417
icmp_type = dict (type = 'int' ),
0 commit comments