Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_router_multicast.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3
4 # Copyright: (c) 2022 Fortinet
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 __metaclass__ = type
13
14 ANSIBLE_METADATA = {
15 "status": ["preview"],
16 "supported_by": "community",
17 "metadata_version": "1.1",
18 }
19
20 DOCUMENTATION = """
21 ---
22 module: fortios_router_multicast
23 short_description: Configure router multicast in Fortinet's FortiOS and FortiGate.
24 description:
25 - This module is able to configure a FortiGate or FortiOS (FOS) device by allowing the
26 user to set and modify router feature and multicast category.
27 Examples include all parameters and values need to be adjusted to datasources before usage.
28 Tested with FOS v6.0.0
29 version_added: "2.0.0"
30 author:
31 - Link Zheng (@chillancezen)
32 - Jie Xue (@JieX19)
33 - Hongbin Lu (@fgtdev-hblu)
34 - Frank Shen (@frankshen01)
35 - Miguel Angel Munoz (@mamunozgonzalez)
36 - Nicolas Thomas (@thomnico)
37 notes:
38 - Legacy fortiosapi has been deprecated, httpapi is the preferred way to run playbooks
39
40 - The module supports check_mode.
41
42 requirements:
43 - ansible>=2.16
44 options:
45 access_token:
46 description:
47 - Token-based authentication.
48 Generated from GUI of Fortigate.
49 type: str
50 required: false
51 enable_log:
52 description:
53 - Enable/Disable logging for task.
54 type: bool
55 required: false
56 default: false
57 vdom:
58 description:
59 - Virtual domain, among those defined previously. A vdom is a
60 virtual instance of the FortiGate that can be configured and
61 used as a different unit.
62 type: str
63 default: root
64 member_path:
65 type: str
66 description:
67 - Member attribute path to operate on.
68 - Delimited by a slash character if there are more than one attribute.
69 - Parameter marked with member_path is legitimate for doing member operation.
70 member_state:
71 type: str
72 description:
73 - Add or delete a member under specified attribute path.
74 - When member_state is specified, the state option is ignored.
75 choices:
76 - 'present'
77 - 'absent'
78
79 router_multicast:
80 description:
81 - Configure router multicast.
82 default: null
83 type: dict
84 suboptions:
85 interface:
86 description:
87 - PIM interfaces.
88 type: list
89 elements: dict
90 suboptions:
91 bfd:
92 description:
93 - Enable/disable Protocol Independent Multicast (PIM) Bidirectional Forwarding Detection (BFD).
94 type: str
95 choices:
96 - 'enable'
97 - 'disable'
98 cisco_exclude_genid:
99 description:
100 - Exclude GenID from hello packets (compatibility with old Cisco IOS).
101 type: str
102 choices:
103 - 'enable'
104 - 'disable'
105 dr_priority:
106 description:
107 - DR election priority.
108 type: int
109 hello_holdtime:
110 description:
111 - Time before old neighbor information expires (0 - 65535 sec).
112 type: int
113 hello_interval:
114 description:
115 - Interval between sending PIM hello messages (0 - 65535 sec).
116 type: int
117 igmp:
118 description:
119 - IGMP configuration options.
120 type: dict
121 suboptions:
122 access_group:
123 description:
124 - Groups IGMP hosts are allowed to join. Source router.access-list.name.
125 type: str
126 immediate_leave_group:
127 description:
128 - Groups to drop membership for immediately after receiving IGMPv2 leave. Source router.access-list.name.
129 type: str
130 last_member_query_count:
131 description:
132 - Number of group specific queries before removing group (2 - 7).
133 type: int
134 last_member_query_interval:
135 description:
136 - Timeout between IGMPv2 leave and removing group (1 - 65535 msec).
137 type: int
138 query_interval:
139 description:
140 - Interval between queries to IGMP hosts (1 - 65535 sec).
141 type: int
142 query_max_response_time:
143 description:
144 - Maximum time to wait for a IGMP query response (1 - 25 sec).
145 type: int
146 query_timeout:
147 description:
148 - Timeout between queries before becoming querying unit for network (60 - 900).
149 type: int
150 router_alert_check:
151 description:
152 - Enable/disable require IGMP packets contain router alert option.
153 type: str
154 choices:
155 - 'enable'
156 - 'disable'
157 version:
158 description:
159 - Maximum version of IGMP to support.
160 type: str
161 choices:
162 - '3'
163 - '2'
164 - '1'
165 join_group:
166 description:
167 - Join multicast groups.
168 type: list
169 elements: dict
170 suboptions:
171 address:
172 description:
173 - Multicast group IP address.
174 required: true
175 type: str
176 multicast_flow:
177 description:
178 - Acceptable source for multicast group. Source router.multicast-flow.name.
179 type: str
180 name:
181 description:
182 - Interface name. Source system.interface.name.
183 required: true
184 type: str
185 neighbour_filter:
186 description:
187 - Routers acknowledged as neighbor routers. Source router.access-list.name.
188 type: str
189 passive:
190 description:
191 - Enable/disable listening to IGMP but not participating in PIM.
192 type: str
193 choices:
194 - 'enable'
195 - 'disable'
196 pim_mode:
197 description:
198 - PIM operation mode.
199 type: str
200 choices:
201 - 'sparse-mode'
202 - 'dense-mode'
203 propagation_delay:
204 description:
205 - Delay flooding packets on this interface (100 - 5000 msec).
206 type: int
207 rp_candidate:
208 description:
209 - Enable/disable compete to become RP in elections.
210 type: str
211 choices:
212 - 'enable'
213 - 'disable'
214 rp_candidate_group:
215 description:
216 - Multicast groups managed by this RP. Source router.access-list.name.
217 type: str
218 rp_candidate_interval:
219 description:
220 - RP candidate advertisement interval (1 - 16383 sec).
221 type: int
222 rp_candidate_priority:
223 description:
224 - Router"s priority as RP.
225 type: int
226 rpf_nbr_fail_back:
227 description:
228 - Enable/disable fail back for RPF neighbor query.
229 type: str
230 choices:
231 - 'enable'
232 - 'disable'
233 rpf_nbr_fail_back_filter:
234 description:
235 - Filter for fail back RPF neighbors. Source router.access-list.name.
236 type: str
237 state_refresh_interval:
238 description:
239 - Interval between sending state-refresh packets (1 - 100 sec).
240 type: int
241 static_group:
242 description:
243 - Statically set multicast groups to forward out. Source router.multicast-flow.name.
244 type: str
245 ttl_threshold:
246 description:
247 - Minimum TTL of multicast packets that will be forwarded (applied only to new multicast routes) (1 - 255).
248 type: int
249 multicast_routing:
250 description:
251 - Enable/disable IP multicast routing.
252 type: str
253 choices:
254 - 'enable'
255 - 'disable'
256 pim_sm_global:
257 description:
258 - PIM sparse-mode global settings.
259 type: dict
260 suboptions:
261 accept_register_list:
262 description:
263 - Sources allowed to register packets with this Rendezvous Point (RP). Source router.access-list.name.
264 type: str
265 accept_source_list:
266 description:
267 - Sources allowed to send multicast traffic. Source router.access-list.name.
268 type: str
269 bsr_allow_quick_refresh:
270 description:
271 - Enable/disable accept BSR quick refresh packets from neighbors.
272 type: str
273 choices:
274 - 'enable'
275 - 'disable'
276 bsr_candidate:
277 description:
278 - Enable/disable allowing this router to become a bootstrap router (BSR).
279 type: str
280 choices:
281 - 'enable'
282 - 'disable'
283 bsr_hash:
284 description:
285 - BSR hash length (0 - 32).
286 type: int
287 bsr_interface:
288 description:
289 - Interface to advertise as candidate BSR. Source system.interface.name.
290 type: str
291 bsr_priority:
292 description:
293 - BSR priority (0 - 255).
294 type: int
295 cisco_crp_prefix:
296 description:
297 - Enable/disable making candidate RP compatible with old Cisco IOS.
298 type: str
299 choices:
300 - 'enable'
301 - 'disable'
302 cisco_ignore_rp_set_priority:
303 description:
304 - Use only hash for RP selection (compatibility with old Cisco IOS).
305 type: str
306 choices:
307 - 'enable'
308 - 'disable'
309 cisco_register_checksum:
310 description:
311 - Checksum entire register packet(for old Cisco IOS compatibility).
312 type: str
313 choices:
314 - 'enable'
315 - 'disable'
316 cisco_register_checksum_group:
317 description:
318 - Cisco register checksum only these groups. Source router.access-list.name.
319 type: str
320 join_prune_holdtime:
321 description:
322 - Join/prune holdtime (1 - 65535).
323 type: int
324 message_interval:
325 description:
326 - Period of time between sending periodic PIM join/prune messages in seconds (1 - 65535).
327 type: int
328 null_register_retries:
329 description:
330 - Maximum retries of null register (1 - 20).
331 type: int
332 pim_use_sdwan:
333 description:
334 - Enable/disable use of SDWAN when checking RPF neighbor and sending of REG packet.
335 type: str
336 choices:
337 - 'enable'
338 - 'disable'
339 register_rate_limit:
340 description:
341 - Limit of packets/sec per source registered through this RP (0 - 65535).
342 type: int
343 register_rp_reachability:
344 description:
345 - Enable/disable check RP is reachable before registering packets.
346 type: str
347 choices:
348 - 'enable'
349 - 'disable'
350 register_source:
351 description:
352 - Override source address in register packets.
353 type: str
354 choices:
355 - 'disable'
356 - 'interface'
357 - 'ip-address'
358 register_source_interface:
359 description:
360 - Override with primary interface address. Source system.interface.name.
361 type: str
362 register_source_ip:
363 description:
364 - Override with local IP address.
365 type: str
366 register_supression:
367 description:
368 - Period of time to honor register-stop message (1 - 65535 sec).
369 type: int
370 rp_address:
371 description:
372 - Statically configure RP addresses.
373 type: list
374 elements: dict
375 suboptions:
376 group:
377 description:
378 - Groups to use this RP. Source router.access-list.name.
379 type: str
380 id:
381 description:
382 - ID. see <a href='#notes'>Notes</a>.
383 required: true
384 type: int
385 ip_address:
386 description:
387 - RP router address.
388 type: str
389 rp_register_keepalive:
390 description:
391 - Timeout for RP receiving data on (S,G) tree (1 - 65535 sec).
392 type: int
393 spt_threshold:
394 description:
395 - Enable/disable switching to source specific trees.
396 type: str
397 choices:
398 - 'enable'
399 - 'disable'
400 spt_threshold_group:
401 description:
402 - Groups allowed to switch to source tree. Source router.access-list.name.
403 type: str
404 ssm:
405 description:
406 - Enable/disable source specific multicast.
407 type: str
408 choices:
409 - 'enable'
410 - 'disable'
411 ssm_range:
412 description:
413 - Groups allowed to source specific multicast. Source router.access-list.name.
414 type: str
415 pim_sm_global_vrf:
416 description:
417 - per-VRF PIM sparse-mode global settings.
418 type: list
419 elements: dict
420 suboptions:
421 bsr_allow_quick_refresh:
422 description:
423 - Enable/disable accept BSR quick refresh packets from neighbors.
424 type: str
425 choices:
426 - 'enable'
427 - 'disable'
428 bsr_candidate:
429 description:
430 - Enable/disable allowing this router to become a bootstrap router (BSR).
431 type: str
432 choices:
433 - 'enable'
434 - 'disable'
435 bsr_hash:
436 description:
437 - BSR hash length (0 - 32).
438 type: int
439 bsr_interface:
440 description:
441 - Interface to advertise as candidate BSR. Source system.interface.name.
442 type: str
443 bsr_priority:
444 description:
445 - BSR priority (0 - 255).
446 type: int
447 cisco_crp_prefix:
448 description:
449 - Enable/disable making candidate RP compatible with old Cisco IOS.
450 type: str
451 choices:
452 - 'enable'
453 - 'disable'
454 rp_address:
455 description:
456 - Statically configure RP addresses.
457 type: list
458 elements: dict
459 suboptions:
460 group:
461 description:
462 - Groups to use this RP. Source router.access-list.name.
463 type: str
464 id:
465 description:
466 - ID. see <a href='#notes'>Notes</a>.
467 required: true
468 type: int
469 ip_address:
470 description:
471 - RP router address.
472 type: str
473 vrf:
474 description:
475 - VRF ID. see <a href='#notes'>Notes</a>.
476 required: true
477 type: int
478 route_limit:
479 description:
480 - Maximum number of multicast routes.
481 type: int
482 route_threshold:
483 description:
484 - Generate warnings when the number of multicast routes exceeds this number, must not be greater than route-limit.
485 type: int
486 """
487
488 EXAMPLES = """
489 - name: Configure router multicast.
490 fortinet.fortios.fortios_router_multicast:
491 vdom: "{{ vdom }}"
492 router_multicast:
493 interface:
494 -
495 bfd: "enable"
496 cisco_exclude_genid: "enable"
497 dr_priority: "1"
498 hello_holdtime: "105"
499 hello_interval: "30"
500 igmp:
501 access_group: "<your_own_value> (source router.access-list.name)"
502 immediate_leave_group: "<your_own_value> (source router.access-list.name)"
503 last_member_query_count: "2"
504 last_member_query_interval: "1000"
505 query_interval: "125"
506 query_max_response_time: "10"
507 query_timeout: "255"
508 router_alert_check: "enable"
509 version: "3"
510 join_group:
511 -
512 address: "<your_own_value>"
513 multicast_flow: "<your_own_value> (source router.multicast-flow.name)"
514 name: "default_name_22 (source system.interface.name)"
515 neighbour_filter: "<your_own_value> (source router.access-list.name)"
516 passive: "enable"
517 pim_mode: "sparse-mode"
518 propagation_delay: "500"
519 rp_candidate: "enable"
520 rp_candidate_group: "<your_own_value> (source router.access-list.name)"
521 rp_candidate_interval: "60"
522 rp_candidate_priority: "192"
523 rpf_nbr_fail_back: "enable"
524 rpf_nbr_fail_back_filter: "<your_own_value> (source router.access-list.name)"
525 state_refresh_interval: "60"
526 static_group: "<your_own_value> (source router.multicast-flow.name)"
527 ttl_threshold: "1"
528 multicast_routing: "enable"
529 pim_sm_global:
530 accept_register_list: "<your_own_value> (source router.access-list.name)"
531 accept_source_list: "<your_own_value> (source router.access-list.name)"
532 bsr_allow_quick_refresh: "enable"
533 bsr_candidate: "enable"
534 bsr_hash: "10"
535 bsr_interface: "<your_own_value> (source system.interface.name)"
536 bsr_priority: "0"
537 cisco_crp_prefix: "enable"
538 cisco_ignore_rp_set_priority: "enable"
539 cisco_register_checksum: "enable"
540 cisco_register_checksum_group: "<your_own_value> (source router.access-list.name)"
541 join_prune_holdtime: "210"
542 message_interval: "60"
543 null_register_retries: "1"
544 pim_use_sdwan: "enable"
545 register_rate_limit: "0"
546 register_rp_reachability: "enable"
547 register_source: "disable"
548 register_source_interface: "<your_own_value> (source system.interface.name)"
549 register_source_ip: "<your_own_value>"
550 register_supression: "60"
551 rp_address:
552 -
553 group: "<your_own_value> (source router.access-list.name)"
554 id: "61"
555 ip_address: "<your_own_value>"
556 rp_register_keepalive: "185"
557 spt_threshold: "enable"
558 spt_threshold_group: "<your_own_value> (source router.access-list.name)"
559 ssm: "enable"
560 ssm_range: "<your_own_value> (source router.access-list.name)"
561 pim_sm_global_vrf:
562 -
563 bsr_allow_quick_refresh: "enable"
564 bsr_candidate: "enable"
565 bsr_hash: "10"
566 bsr_interface: "<your_own_value> (source system.interface.name)"
567 bsr_priority: "0"
568 cisco_crp_prefix: "enable"
569 rp_address:
570 -
571 group: "<your_own_value> (source router.access-list.name)"
572 id: "77"
573 ip_address: "<your_own_value>"
574 vrf: "<you_own_value>"
575 route_limit: "2147483647"
576 route_threshold: ""
577 """
578
579 RETURN = """
580 build:
581 description: Build number of the fortigate image
582 returned: always
583 type: str
584 sample: '1547'
585 http_method:
586 description: Last method used to provision the content into FortiGate
587 returned: always
588 type: str
589 sample: 'PUT'
590 http_status:
591 description: Last result given by FortiGate on last operation applied
592 returned: always
593 type: str
594 sample: "200"
595 mkey:
596 description: Master key (id) used in the last call to FortiGate
597 returned: success
598 type: str
599 sample: "id"
600 name:
601 description: Name of the table used to fulfill the request
602 returned: always
603 type: str
604 sample: "urlfilter"
605 path:
606 description: Path of the table used to fulfill the request
607 returned: always
608 type: str
609 sample: "webfilter"
610 revision:
611 description: Internal revision number
612 returned: always
613 type: str
614 sample: "17.0.2.10658"
615 serial:
616 description: Serial number of the unit
617 returned: always
618 type: str
619 sample: "FGVMEVYYQT3AB5352"
620 status:
621 description: Indication of the operation's result
622 returned: always
623 type: str
624 sample: "success"
625 vdom:
626 description: Virtual domain used
627 returned: always
628 type: str
629 sample: "root"
630 version:
631 description: Version of the FortiGate
632 returned: always
633 type: str
634 sample: "v5.6.3"
635 """
636 from ansible.module_utils.basic import AnsibleModule
637 from ansible.module_utils.connection import Connection
638 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
639 FortiOSHandler,
640 )
641 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
642 check_legacy_fortiosapi,
643 )
644 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
645 schema_to_module_spec,
646 )
647 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
648 check_schema_versioning,
649 )
650 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
651 FAIL_SOCKET_MSG,
652 )
653 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
654 remove_invalid_fields,
655 )
656 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
657 is_same_comparison,
658 )
659 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
660 serialize,
661 )
662 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
663 find_current_values,
664 )
665 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
666 unify_data_format,
667 )
668
669
670 def filter_router_multicast_data(json):
671 option_list = [
672 "interface",
673 "multicast_routing",
674 "pim_sm_global",
675 "pim_sm_global_vrf",
676 "route_limit",
677 "route_threshold",
678 ]
679
680 json = remove_invalid_fields(json)
681 dictionary = {}
682
683 for attribute in option_list:
684 if attribute in json and json[attribute] is not None:
685 dictionary[attribute] = json[attribute]
686
687 return dictionary
688
689
690 def underscore_to_hyphen(data):
691 new_data = None
692 if isinstance(data, list):
693 new_data = []
694 for i, elem in enumerate(data):
695 new_data.append(underscore_to_hyphen(elem))
696 elif isinstance(data, dict):
697 new_data = {}
698 for k, v in data.items():
699 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
700 else:
701 return data
702 return new_data
703
704
705 def router_multicast(data, fos, check_mode=False):
706
707 state = None
708 vdom = data["vdom"]
709 parameters = None
710 state = data.get("state", None)
711 router_multicast_data = data["router_multicast"]
712
713 filtered_data = filter_router_multicast_data(router_multicast_data)
714 converted_data = underscore_to_hyphen(filtered_data)
715
716 # check_mode starts from here
717 if check_mode:
718 diff = {
719 "before": "",
720 "after": filtered_data,
721 }
722 mkeyname = fos.get_mkeyname(None, None)
723 mkey = fos.get_mkey("router", "multicast", filtered_data, vdom=vdom)
724 current_data = fos.get(
725 "router", "multicast", vdom=vdom, mkey=mkey, parameters=parameters
726 )
727 is_existed = (
728 current_data
729 and current_data.get("http_status") == 200
730 and (
731 mkeyname
732 and isinstance(current_data.get("results"), list)
733 and len(current_data["results"]) > 0
734 or not mkeyname
735 and current_data["results"] # global object response
736 )
737 )
738
739 # 2. if it exists and the state is 'present' then compare current settings with desired
740 if state == "present" or state is True or state is None:
741 # for non global modules, mkeyname must exist and it's a new module when mkey is None
742 if mkeyname is not None and mkey is None:
743 return False, True, filtered_data, diff
744
745 # if mkey exists then compare each other
746 # record exits and they're matched or not
747 copied_filtered_data = filtered_data.copy()
748 copied_filtered_data.pop(mkeyname, None)
749 unified_filtered_data = unify_data_format(copied_filtered_data)
750
751 current_data_results = current_data.get("results", {})
752 current_config = (
753 current_data_results[0]
754 if mkeyname
755 and isinstance(current_data_results, list)
756 and len(current_data_results) > 0
757 else current_data_results
758 )
759 if is_existed:
760 unified_current_values = find_current_values(
761 unified_filtered_data,
762 unify_data_format(current_config),
763 )
764
765 is_same = is_same_comparison(
766 serialize(unified_current_values), serialize(unified_filtered_data)
767 )
768
769 return (
770 False,
771 not is_same,
772 filtered_data,
773 {"before": unified_current_values, "after": unified_filtered_data},
774 )
775
776 # record does not exist
777 return False, True, filtered_data, diff
778
779 if state == "absent":
780 if mkey is None:
781 return (
782 False,
783 False,
784 filtered_data,
785 {"before": current_data["results"][0], "after": ""},
786 )
787
788 if is_existed:
789 return (
790 False,
791 True,
792 filtered_data,
793 {"before": current_data["results"][0], "after": ""},
794 )
795 return False, False, filtered_data, {}
796
797 return True, False, {"reason: ": "Must provide state parameter"}, {}
798 # pass post processed data to member operations
799 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
800 data_copy = data.copy()
801 data_copy["router_multicast"] = filtered_data
802 fos.do_member_operation(
803 "router",
804 "multicast",
805 data_copy,
806 )
807
808 return fos.set(
809 "router", "multicast", data=converted_data, vdom=vdom, parameters=parameters
810 )
811
812
813 def is_successful_status(resp):
814 return (
815 "status" in resp
816 and resp["status"] == "success"
817 or "http_status" in resp
818 and resp["http_status"] == 200
819 or "http_method" in resp
820 and resp["http_method"] == "DELETE"
821 and resp["http_status"] == 404
822 )
823
824
825 def fortios_router(data, fos, check_mode):
826
827 if data["router_multicast"]:
828 resp = router_multicast(data, fos, check_mode)
829 else:
830 fos._module.fail_json(msg="missing task body: %s" % ("router_multicast"))
831 if isinstance(resp, tuple) and len(resp) == 4:
832 return resp
833 return (
834 not is_successful_status(resp),
835 is_successful_status(resp)
836 and (resp["revision_changed"] if "revision_changed" in resp else True),
837 resp,
838 {},
839 )
840
841
842 versioned_schema = {
843 "v_range": [["v6.0.0", ""]],
844 "type": "dict",
845 "children": {
846 "route_threshold": {"v_range": [["v6.0.0", ""]], "type": "integer"},
847 "route_limit": {"v_range": [["v6.0.0", ""]], "type": "integer"},
848 "multicast_routing": {
849 "v_range": [["v6.0.0", ""]],
850 "type": "string",
851 "options": [{"value": "enable"}, {"value": "disable"}],
852 },
853 "pim_sm_global": {
854 "v_range": [["v6.0.0", ""]],
855 "type": "dict",
856 "children": {
857 "message_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
858 "join_prune_holdtime": {"v_range": [["v6.0.0", ""]], "type": "integer"},
859 "accept_register_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
860 "accept_source_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
861 "bsr_candidate": {
862 "v_range": [["v6.0.0", ""]],
863 "type": "string",
864 "options": [{"value": "enable"}, {"value": "disable"}],
865 },
866 "bsr_interface": {"v_range": [["v6.0.0", ""]], "type": "string"},
867 "bsr_priority": {"v_range": [["v6.0.0", ""]], "type": "integer"},
868 "bsr_hash": {"v_range": [["v6.0.0", ""]], "type": "integer"},
869 "bsr_allow_quick_refresh": {
870 "v_range": [["v6.0.0", ""]],
871 "type": "string",
872 "options": [{"value": "enable"}, {"value": "disable"}],
873 },
874 "cisco_crp_prefix": {
875 "v_range": [["v6.0.0", ""]],
876 "type": "string",
877 "options": [{"value": "enable"}, {"value": "disable"}],
878 },
879 "cisco_register_checksum": {
880 "v_range": [["v6.0.0", ""]],
881 "type": "string",
882 "options": [{"value": "enable"}, {"value": "disable"}],
883 },
884 "cisco_register_checksum_group": {
885 "v_range": [["v6.0.0", ""]],
886 "type": "string",
887 },
888 "cisco_ignore_rp_set_priority": {
889 "v_range": [["v6.0.0", ""]],
890 "type": "string",
891 "options": [{"value": "enable"}, {"value": "disable"}],
892 },
893 "register_rp_reachability": {
894 "v_range": [["v6.0.0", ""]],
895 "type": "string",
896 "options": [{"value": "enable"}, {"value": "disable"}],
897 },
898 "register_source": {
899 "v_range": [["v6.0.0", ""]],
900 "type": "string",
901 "options": [
902 {"value": "disable"},
903 {"value": "interface"},
904 {"value": "ip-address"},
905 ],
906 },
907 "register_source_interface": {
908 "v_range": [["v6.0.0", ""]],
909 "type": "string",
910 },
911 "register_source_ip": {"v_range": [["v6.0.0", ""]], "type": "string"},
912 "register_supression": {"v_range": [["v6.0.0", ""]], "type": "integer"},
913 "null_register_retries": {
914 "v_range": [["v6.0.0", ""]],
915 "type": "integer",
916 },
917 "rp_register_keepalive": {
918 "v_range": [["v6.0.0", ""]],
919 "type": "integer",
920 },
921 "spt_threshold": {
922 "v_range": [["v6.0.0", ""]],
923 "type": "string",
924 "options": [{"value": "enable"}, {"value": "disable"}],
925 },
926 "spt_threshold_group": {"v_range": [["v6.0.0", ""]], "type": "string"},
927 "ssm": {
928 "v_range": [["v6.0.0", ""]],
929 "type": "string",
930 "options": [{"value": "enable"}, {"value": "disable"}],
931 },
932 "ssm_range": {"v_range": [["v6.0.0", ""]], "type": "string"},
933 "register_rate_limit": {"v_range": [["v6.0.0", ""]], "type": "integer"},
934 "pim_use_sdwan": {
935 "v_range": [["v7.4.0", ""]],
936 "type": "string",
937 "options": [{"value": "enable"}, {"value": "disable"}],
938 },
939 "rp_address": {
940 "type": "list",
941 "elements": "dict",
942 "children": {
943 "id": {
944 "v_range": [["v6.0.0", ""]],
945 "type": "integer",
946 "required": True,
947 },
948 "ip_address": {"v_range": [["v6.0.0", ""]], "type": "string"},
949 "group": {"v_range": [["v6.0.0", ""]], "type": "string"},
950 },
951 "v_range": [["v6.0.0", ""]],
952 },
953 },
954 },
955 "pim_sm_global_vrf": {
956 "type": "list",
957 "elements": "dict",
958 "children": {
959 "vrf": {
960 "v_range": [["v7.6.1", ""]],
961 "type": "integer",
962 "required": True,
963 },
964 "bsr_candidate": {
965 "v_range": [["v7.6.1", ""]],
966 "type": "string",
967 "options": [{"value": "enable"}, {"value": "disable"}],
968 },
969 "bsr_interface": {"v_range": [["v7.6.1", ""]], "type": "string"},
970 "bsr_priority": {"v_range": [["v7.6.1", ""]], "type": "integer"},
971 "bsr_hash": {"v_range": [["v7.6.1", ""]], "type": "integer"},
972 "bsr_allow_quick_refresh": {
973 "v_range": [["v7.6.1", ""]],
974 "type": "string",
975 "options": [{"value": "enable"}, {"value": "disable"}],
976 },
977 "cisco_crp_prefix": {
978 "v_range": [["v7.6.1", ""]],
979 "type": "string",
980 "options": [{"value": "enable"}, {"value": "disable"}],
981 },
982 "rp_address": {
983 "type": "list",
984 "elements": "dict",
985 "children": {
986 "id": {
987 "v_range": [["v7.6.1", ""]],
988 "type": "integer",
989 "required": True,
990 },
991 "ip_address": {"v_range": [["v7.6.1", ""]], "type": "string"},
992 "group": {"v_range": [["v7.6.1", ""]], "type": "string"},
993 },
994 "v_range": [["v7.6.1", ""]],
995 },
996 },
997 "v_range": [["v7.6.1", ""]],
998 },
999 "interface": {
1000 "type": "list",
1001 "elements": "dict",
1002 "children": {
1003 "name": {
1004 "v_range": [["v6.0.0", ""]],
1005 "type": "string",
1006 "required": True,
1007 },
1008 "ttl_threshold": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1009 "pim_mode": {
1010 "v_range": [["v6.0.0", ""]],
1011 "type": "string",
1012 "options": [{"value": "sparse-mode"}, {"value": "dense-mode"}],
1013 },
1014 "passive": {
1015 "v_range": [["v6.0.0", ""]],
1016 "type": "string",
1017 "options": [{"value": "enable"}, {"value": "disable"}],
1018 },
1019 "bfd": {
1020 "v_range": [["v6.0.0", ""]],
1021 "type": "string",
1022 "options": [{"value": "enable"}, {"value": "disable"}],
1023 },
1024 "neighbour_filter": {"v_range": [["v6.0.0", ""]], "type": "string"},
1025 "hello_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1026 "hello_holdtime": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1027 "cisco_exclude_genid": {
1028 "v_range": [["v6.0.0", ""]],
1029 "type": "string",
1030 "options": [{"value": "enable"}, {"value": "disable"}],
1031 },
1032 "dr_priority": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1033 "propagation_delay": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1034 "state_refresh_interval": {
1035 "v_range": [["v6.0.0", ""]],
1036 "type": "integer",
1037 },
1038 "rp_candidate": {
1039 "v_range": [["v6.0.0", ""]],
1040 "type": "string",
1041 "options": [{"value": "enable"}, {"value": "disable"}],
1042 },
1043 "rp_candidate_group": {"v_range": [["v6.0.0", ""]], "type": "string"},
1044 "rp_candidate_priority": {
1045 "v_range": [["v6.0.0", ""]],
1046 "type": "integer",
1047 },
1048 "rp_candidate_interval": {
1049 "v_range": [["v6.0.0", ""]],
1050 "type": "integer",
1051 },
1052 "multicast_flow": {"v_range": [["v6.0.0", ""]], "type": "string"},
1053 "static_group": {"v_range": [["v6.0.0", ""]], "type": "string"},
1054 "rpf_nbr_fail_back": {
1055 "v_range": [["v6.2.0", ""]],
1056 "type": "string",
1057 "options": [{"value": "enable"}, {"value": "disable"}],
1058 },
1059 "rpf_nbr_fail_back_filter": {
1060 "v_range": [["v6.2.0", ""]],
1061 "type": "string",
1062 },
1063 "join_group": {
1064 "type": "list",
1065 "elements": "dict",
1066 "children": {
1067 "address": {
1068 "v_range": [["v6.0.0", ""]],
1069 "type": "string",
1070 "required": True,
1071 }
1072 },
1073 "v_range": [["v6.0.0", ""]],
1074 },
1075 "igmp": {
1076 "v_range": [["v6.0.0", ""]],
1077 "type": "dict",
1078 "children": {
1079 "access_group": {"v_range": [["v6.0.0", ""]], "type": "string"},
1080 "version": {
1081 "v_range": [["v6.0.0", ""]],
1082 "type": "string",
1083 "options": [{"value": "3"}, {"value": "2"}, {"value": "1"}],
1084 },
1085 "immediate_leave_group": {
1086 "v_range": [["v6.0.0", ""]],
1087 "type": "string",
1088 },
1089 "last_member_query_interval": {
1090 "v_range": [["v6.0.0", ""]],
1091 "type": "integer",
1092 },
1093 "last_member_query_count": {
1094 "v_range": [["v6.0.0", ""]],
1095 "type": "integer",
1096 },
1097 "query_max_response_time": {
1098 "v_range": [["v6.0.0", ""]],
1099 "type": "integer",
1100 },
1101 "query_interval": {
1102 "v_range": [["v6.0.0", ""]],
1103 "type": "integer",
1104 },
1105 "query_timeout": {
1106 "v_range": [["v6.0.0", ""]],
1107 "type": "integer",
1108 },
1109 "router_alert_check": {
1110 "v_range": [["v6.0.0", ""]],
1111 "type": "string",
1112 "options": [{"value": "enable"}, {"value": "disable"}],
1113 },
1114 },
1115 },
1116 },
1117 "v_range": [["v6.0.0", ""]],
1118 },
1119 },
1120 }
1121
1122
1123 def main():
1124 module_spec = schema_to_module_spec(versioned_schema)
1125 mkeyname = None
1126 fields = {
1127 "access_token": {"required": False, "type": "str", "no_log": True},
1128 "enable_log": {"required": False, "type": "bool", "default": False},
1129 "vdom": {"required": False, "type": "str", "default": "root"},
1130 "member_path": {"required": False, "type": "str"},
1131 "member_state": {
1132 "type": "str",
1133 "required": False,
1134 "choices": ["present", "absent"],
1135 },
1136 "router_multicast": {
1137 "required": False,
1138 "type": "dict",
1139 "default": None,
1140 "options": {},
1141 },
1142 }
1143 for attribute_name in module_spec["options"]:
1144 fields["router_multicast"]["options"][attribute_name] = module_spec["options"][
1145 attribute_name
1146 ]
1147 if mkeyname and mkeyname == attribute_name:
1148 fields["router_multicast"]["options"][attribute_name]["required"] = True
1149
1150 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
1151 check_legacy_fortiosapi(module)
1152
1153 is_error = False
1154 has_changed = False
1155 result = None
1156 diff = None
1157
1158 versions_check_result = None
1159 if module._socket_path:
1160 connection = Connection(module._socket_path)
1161 if "access_token" in module.params:
1162 connection.set_custom_option("access_token", module.params["access_token"])
1163
1164 if "enable_log" in module.params:
1165 connection.set_custom_option("enable_log", module.params["enable_log"])
1166 else:
1167 connection.set_custom_option("enable_log", False)
1168 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
1169 versions_check_result = check_schema_versioning(
1170 fos, versioned_schema, "router_multicast"
1171 )
1172
1173 is_error, has_changed, result, diff = fortios_router(
1174 module.params, fos, module.check_mode
1175 )
1176
1177 else:
1178 module.fail_json(**FAIL_SOCKET_MSG)
1179
1180 if versions_check_result and versions_check_result["matched"] is False:
1181 module.warn(
1182 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
1183 )
1184
1185 if not is_error:
1186 if versions_check_result and versions_check_result["matched"] is False:
1187 module.exit_json(
1188 changed=has_changed,
1189 version_check_warning=versions_check_result,
1190 meta=result,
1191 diff=diff,
1192 )
1193 else:
1194 module.exit_json(changed=has_changed, meta=result, diff=diff)
1195 else:
1196 if versions_check_result and versions_check_result["matched"] is False:
1197 module.fail_json(
1198 msg="Error in repo",
1199 version_check_warning=versions_check_result,
1200 meta=result,
1201 )
1202 else:
1203 module.fail_json(msg="Error in repo", meta=result)
1204
1205
1206 if __name__ == "__main__":
1207 main()