Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_router_ospf6.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_ospf6
23 short_description: Configure IPv6 OSPF 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 ospf6 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_ospf6:
80 description:
81 - Configure IPv6 OSPF.
82 default: null
83 type: dict
84 suboptions:
85 abr_type:
86 description:
87 - Area border router type.
88 type: str
89 choices:
90 - 'cisco'
91 - 'ibm'
92 - 'standard'
93 area:
94 description:
95 - OSPF6 area configuration.
96 type: list
97 elements: dict
98 suboptions:
99 authentication:
100 description:
101 - Authentication mode.
102 type: str
103 choices:
104 - 'none'
105 - 'ah'
106 - 'esp'
107 default_cost:
108 description:
109 - Summary default cost of stub or NSSA area.
110 type: int
111 id:
112 description:
113 - Area entry IP address.
114 required: true
115 type: str
116 ipsec_auth_alg:
117 description:
118 - Authentication algorithm.
119 type: str
120 choices:
121 - 'md5'
122 - 'sha1'
123 - 'sha256'
124 - 'sha384'
125 - 'sha512'
126 ipsec_enc_alg:
127 description:
128 - Encryption algorithm.
129 type: str
130 choices:
131 - 'null'
132 - 'des'
133 - '3des'
134 - 'aes128'
135 - 'aes192'
136 - 'aes256'
137 ipsec_keys:
138 description:
139 - IPsec authentication and encryption keys.
140 type: list
141 elements: dict
142 suboptions:
143 auth_key:
144 description:
145 - Authentication key.
146 type: str
147 enc_key:
148 description:
149 - Encryption key.
150 type: str
151 spi:
152 description:
153 - Security Parameters Index. see <a href='#notes'>Notes</a>.
154 required: true
155 type: int
156 key_rollover_interval:
157 description:
158 - Key roll-over interval.
159 type: int
160 nssa_default_information_originate:
161 description:
162 - Enable/disable originate type 7 default into NSSA area.
163 type: str
164 choices:
165 - 'enable'
166 - 'disable'
167 nssa_default_information_originate_metric:
168 description:
169 - OSPFv3 default metric.
170 type: int
171 nssa_default_information_originate_metric_type:
172 description:
173 - OSPFv3 metric type for default routes.
174 type: str
175 choices:
176 - '1'
177 - '2'
178 nssa_redistribution:
179 description:
180 - Enable/disable redistribute into NSSA area.
181 type: str
182 choices:
183 - 'enable'
184 - 'disable'
185 nssa_translator_role:
186 description:
187 - NSSA translator role type.
188 type: str
189 choices:
190 - 'candidate'
191 - 'never'
192 - 'always'
193 range:
194 description:
195 - OSPF6 area range configuration.
196 type: list
197 elements: dict
198 suboptions:
199 advertise:
200 description:
201 - Enable/disable advertise status.
202 type: str
203 choices:
204 - 'disable'
205 - 'enable'
206 id:
207 description:
208 - Range entry ID. see <a href='#notes'>Notes</a>.
209 required: true
210 type: int
211 prefix6:
212 description:
213 - IPv6 prefix.
214 type: str
215 stub_type:
216 description:
217 - Stub summary setting.
218 type: str
219 choices:
220 - 'no-summary'
221 - 'summary'
222 type:
223 description:
224 - Area type setting.
225 type: str
226 choices:
227 - 'regular'
228 - 'nssa'
229 - 'stub'
230 virtual_link:
231 description:
232 - OSPF6 virtual link configuration.
233 type: list
234 elements: dict
235 suboptions:
236 authentication:
237 description:
238 - Authentication mode.
239 type: str
240 choices:
241 - 'none'
242 - 'ah'
243 - 'esp'
244 - 'area'
245 dead_interval:
246 description:
247 - Dead interval.
248 type: int
249 hello_interval:
250 description:
251 - Hello interval.
252 type: int
253 ipsec_auth_alg:
254 description:
255 - Authentication algorithm.
256 type: str
257 choices:
258 - 'md5'
259 - 'sha1'
260 - 'sha256'
261 - 'sha384'
262 - 'sha512'
263 ipsec_enc_alg:
264 description:
265 - Encryption algorithm.
266 type: str
267 choices:
268 - 'null'
269 - 'des'
270 - '3des'
271 - 'aes128'
272 - 'aes192'
273 - 'aes256'
274 ipsec_keys:
275 description:
276 - IPsec authentication and encryption keys.
277 type: list
278 elements: dict
279 suboptions:
280 auth_key:
281 description:
282 - Authentication key.
283 type: str
284 enc_key:
285 description:
286 - Encryption key.
287 type: str
288 spi:
289 description:
290 - Security Parameters Index. see <a href='#notes'>Notes</a>.
291 required: true
292 type: int
293 key_rollover_interval:
294 description:
295 - Key roll-over interval.
296 type: int
297 name:
298 description:
299 - Virtual link entry name.
300 required: true
301 type: str
302 peer:
303 description:
304 - A.B.C.D, peer router ID.
305 type: str
306 retransmit_interval:
307 description:
308 - Retransmit interval.
309 type: int
310 transmit_delay:
311 description:
312 - Transmit delay.
313 type: int
314 auto_cost_ref_bandwidth:
315 description:
316 - Reference bandwidth in terms of megabits per second.
317 type: int
318 bfd:
319 description:
320 - Enable/disable Bidirectional Forwarding Detection (BFD).
321 type: str
322 choices:
323 - 'enable'
324 - 'disable'
325 default_information_metric:
326 description:
327 - Default information metric.
328 type: int
329 default_information_metric_type:
330 description:
331 - Default information metric type.
332 type: str
333 choices:
334 - '1'
335 - '2'
336 default_information_originate:
337 description:
338 - Enable/disable generation of default route.
339 type: str
340 choices:
341 - 'enable'
342 - 'always'
343 - 'disable'
344 default_information_route_map:
345 description:
346 - Default information route map. Source router.route-map.name.
347 type: str
348 default_metric:
349 description:
350 - Default metric of redistribute routes.
351 type: int
352 log_neighbour_changes:
353 description:
354 - Log OSPFv3 neighbor changes.
355 type: str
356 choices:
357 - 'enable'
358 - 'disable'
359 ospf6_interface:
360 description:
361 - OSPF6 interface configuration.
362 type: list
363 elements: dict
364 suboptions:
365 area_id:
366 description:
367 - A.B.C.D, in IPv4 address format.
368 type: str
369 authentication:
370 description:
371 - Authentication mode.
372 type: str
373 choices:
374 - 'none'
375 - 'ah'
376 - 'esp'
377 - 'area'
378 bfd:
379 description:
380 - Enable/disable Bidirectional Forwarding Detection (BFD).
381 type: str
382 choices:
383 - 'global'
384 - 'enable'
385 - 'disable'
386 cost:
387 description:
388 - Cost of the interface, value range from 0 to 65535, 0 means auto-cost.
389 type: int
390 dead_interval:
391 description:
392 - Dead interval.
393 type: int
394 hello_interval:
395 description:
396 - Hello interval.
397 type: int
398 interface:
399 description:
400 - Configuration interface name. Source system.interface.name.
401 type: str
402 ipsec_auth_alg:
403 description:
404 - Authentication algorithm.
405 type: str
406 choices:
407 - 'md5'
408 - 'sha1'
409 - 'sha256'
410 - 'sha384'
411 - 'sha512'
412 ipsec_enc_alg:
413 description:
414 - Encryption algorithm.
415 type: str
416 choices:
417 - 'null'
418 - 'des'
419 - '3des'
420 - 'aes128'
421 - 'aes192'
422 - 'aes256'
423 ipsec_keys:
424 description:
425 - IPsec authentication and encryption keys.
426 type: list
427 elements: dict
428 suboptions:
429 auth_key:
430 description:
431 - Authentication key.
432 type: str
433 enc_key:
434 description:
435 - Encryption key.
436 type: str
437 spi:
438 description:
439 - Security Parameters Index. see <a href='#notes'>Notes</a>.
440 required: true
441 type: int
442 key_rollover_interval:
443 description:
444 - Key roll-over interval.
445 type: int
446 mtu:
447 description:
448 - MTU for OSPFv3 packets.
449 type: int
450 mtu_ignore:
451 description:
452 - Enable/disable ignoring MTU field in DBD packets.
453 type: str
454 choices:
455 - 'enable'
456 - 'disable'
457 name:
458 description:
459 - Interface entry name.
460 required: true
461 type: str
462 neighbor:
463 description:
464 - OSPFv3 neighbors are used when OSPFv3 runs on non-broadcast media.
465 type: list
466 elements: dict
467 suboptions:
468 cost:
469 description:
470 - Cost of the interface, value range from 0 to 65535, 0 means auto-cost.
471 type: int
472 ip6:
473 description:
474 - IPv6 link local address of the neighbor.
475 required: true
476 type: str
477 poll_interval:
478 description:
479 - Poll interval time in seconds.
480 type: int
481 priority:
482 description:
483 - Priority.
484 type: int
485 network_type:
486 description:
487 - Network type.
488 type: str
489 choices:
490 - 'broadcast'
491 - 'point-to-point'
492 - 'non-broadcast'
493 - 'point-to-multipoint'
494 - 'point-to-multipoint-non-broadcast'
495 priority:
496 description:
497 - Priority.
498 type: int
499 retransmit_interval:
500 description:
501 - Retransmit interval.
502 type: int
503 status:
504 description:
505 - Enable/disable OSPF6 routing on this interface.
506 type: str
507 choices:
508 - 'disable'
509 - 'enable'
510 transmit_delay:
511 description:
512 - Transmit delay.
513 type: int
514 passive_interface:
515 description:
516 - Passive interface configuration.
517 type: list
518 elements: dict
519 suboptions:
520 name:
521 description:
522 - Passive interface name. Source system.interface.name.
523 required: true
524 type: str
525 redistribute:
526 description:
527 - Redistribute configuration.
528 type: list
529 elements: dict
530 suboptions:
531 metric:
532 description:
533 - Redistribute metric setting.
534 type: int
535 metric_type:
536 description:
537 - Metric type.
538 type: str
539 choices:
540 - '1'
541 - '2'
542 name:
543 description:
544 - Redistribute name.
545 required: true
546 type: str
547 routemap:
548 description:
549 - Route map name. Source router.route-map.name.
550 type: str
551 status:
552 description:
553 - Status.
554 type: str
555 choices:
556 - 'enable'
557 - 'disable'
558 restart_mode:
559 description:
560 - OSPFv3 restart mode (graceful or none).
561 type: str
562 choices:
563 - 'none'
564 - 'graceful-restart'
565 restart_on_topology_change:
566 description:
567 - Enable/disable continuing graceful restart upon topology change.
568 type: str
569 choices:
570 - 'enable'
571 - 'disable'
572 restart_period:
573 description:
574 - Graceful restart period in seconds.
575 type: int
576 router_id:
577 description:
578 - A.B.C.D, in IPv4 address format.
579 type: str
580 spf_timers:
581 description:
582 - SPF calculation frequency.
583 type: str
584 summary_address:
585 description:
586 - IPv6 address summary configuration.
587 type: list
588 elements: dict
589 suboptions:
590 advertise:
591 description:
592 - Enable/disable advertise status.
593 type: str
594 choices:
595 - 'disable'
596 - 'enable'
597 id:
598 description:
599 - Summary address entry ID. see <a href='#notes'>Notes</a>.
600 required: true
601 type: int
602 prefix6:
603 description:
604 - IPv6 prefix.
605 type: str
606 tag:
607 description:
608 - Tag value.
609 type: int
610 """
611
612 EXAMPLES = """
613 - name: Configure IPv6 OSPF.
614 fortinet.fortios.fortios_router_ospf6:
615 vdom: "{{ vdom }}"
616 router_ospf6:
617 abr_type: "cisco"
618 area:
619 -
620 authentication: "none"
621 default_cost: "10"
622 id: "7"
623 ipsec_auth_alg: "md5"
624 ipsec_enc_alg: "null"
625 ipsec_keys:
626 -
627 auth_key: "<your_own_value>"
628 enc_key: "<your_own_value>"
629 spi: "<you_own_value>"
630 key_rollover_interval: "300"
631 nssa_default_information_originate: "enable"
632 nssa_default_information_originate_metric: "10"
633 nssa_default_information_originate_metric_type: "1"
634 nssa_redistribution: "enable"
635 nssa_translator_role: "candidate"
636 range:
637 -
638 advertise: "disable"
639 id: "22"
640 prefix6: "<your_own_value>"
641 stub_type: "no-summary"
642 type: "regular"
643 virtual_link:
644 -
645 authentication: "none"
646 dead_interval: "40"
647 hello_interval: "10"
648 ipsec_auth_alg: "md5"
649 ipsec_enc_alg: "null"
650 ipsec_keys:
651 -
652 auth_key: "<your_own_value>"
653 enc_key: "<your_own_value>"
654 spi: "<you_own_value>"
655 key_rollover_interval: "300"
656 name: "default_name_37"
657 peer: "<your_own_value>"
658 retransmit_interval: "5"
659 transmit_delay: "1"
660 auto_cost_ref_bandwidth: "1000"
661 bfd: "enable"
662 default_information_metric: "10"
663 default_information_metric_type: "1"
664 default_information_originate: "enable"
665 default_information_route_map: "<your_own_value> (source router.route-map.name)"
666 default_metric: "10"
667 log_neighbour_changes: "enable"
668 ospf6_interface:
669 -
670 area_id: "<your_own_value>"
671 authentication: "none"
672 bfd: "global"
673 cost: "0"
674 dead_interval: "0"
675 hello_interval: "0"
676 interface: "<your_own_value> (source system.interface.name)"
677 ipsec_auth_alg: "md5"
678 ipsec_enc_alg: "null"
679 ipsec_keys:
680 -
681 auth_key: "<your_own_value>"
682 enc_key: "<your_own_value>"
683 spi: "<you_own_value>"
684 key_rollover_interval: "300"
685 mtu: "0"
686 mtu_ignore: "enable"
687 name: "default_name_66"
688 neighbor:
689 -
690 cost: "0"
691 ip6: "<your_own_value>"
692 poll_interval: "10"
693 priority: "1"
694 network_type: "broadcast"
695 priority: "1"
696 retransmit_interval: "5"
697 status: "disable"
698 transmit_delay: "1"
699 passive_interface:
700 -
701 name: "default_name_78 (source system.interface.name)"
702 redistribute:
703 -
704 metric: "0"
705 metric_type: "1"
706 name: "default_name_82"
707 routemap: "<your_own_value> (source router.route-map.name)"
708 status: "enable"
709 restart_mode: "none"
710 restart_on_topology_change: "enable"
711 restart_period: "120"
712 router_id: "<your_own_value>"
713 spf_timers: "<your_own_value>"
714 summary_address:
715 -
716 advertise: "disable"
717 id: "92"
718 prefix6: "<your_own_value>"
719 tag: "0"
720 """
721
722 RETURN = """
723 build:
724 description: Build number of the fortigate image
725 returned: always
726 type: str
727 sample: '1547'
728 http_method:
729 description: Last method used to provision the content into FortiGate
730 returned: always
731 type: str
732 sample: 'PUT'
733 http_status:
734 description: Last result given by FortiGate on last operation applied
735 returned: always
736 type: str
737 sample: "200"
738 mkey:
739 description: Master key (id) used in the last call to FortiGate
740 returned: success
741 type: str
742 sample: "id"
743 name:
744 description: Name of the table used to fulfill the request
745 returned: always
746 type: str
747 sample: "urlfilter"
748 path:
749 description: Path of the table used to fulfill the request
750 returned: always
751 type: str
752 sample: "webfilter"
753 revision:
754 description: Internal revision number
755 returned: always
756 type: str
757 sample: "17.0.2.10658"
758 serial:
759 description: Serial number of the unit
760 returned: always
761 type: str
762 sample: "FGVMEVYYQT3AB5352"
763 status:
764 description: Indication of the operation's result
765 returned: always
766 type: str
767 sample: "success"
768 vdom:
769 description: Virtual domain used
770 returned: always
771 type: str
772 sample: "root"
773 version:
774 description: Version of the FortiGate
775 returned: always
776 type: str
777 sample: "v5.6.3"
778 """
779 from ansible.module_utils.basic import AnsibleModule
780 from ansible.module_utils.connection import Connection
781 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
782 FortiOSHandler,
783 )
784 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
785 check_legacy_fortiosapi,
786 )
787 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
788 schema_to_module_spec,
789 )
790 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
791 check_schema_versioning,
792 )
793 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
794 FAIL_SOCKET_MSG,
795 )
796 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
797 remove_invalid_fields,
798 )
799 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
800 is_same_comparison,
801 )
802 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
803 serialize,
804 )
805 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
806 find_current_values,
807 )
808 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
809 unify_data_format,
810 )
811
812
813 def filter_router_ospf6_data(json):
814 option_list = [
815 "abr_type",
816 "area",
817 "auto_cost_ref_bandwidth",
818 "bfd",
819 "default_information_metric",
820 "default_information_metric_type",
821 "default_information_originate",
822 "default_information_route_map",
823 "default_metric",
824 "log_neighbour_changes",
825 "ospf6_interface",
826 "passive_interface",
827 "redistribute",
828 "restart_mode",
829 "restart_on_topology_change",
830 "restart_period",
831 "router_id",
832 "spf_timers",
833 "summary_address",
834 ]
835
836 json = remove_invalid_fields(json)
837 dictionary = {}
838
839 for attribute in option_list:
840 if attribute in json and json[attribute] is not None:
841 dictionary[attribute] = json[attribute]
842
843 return dictionary
844
845
846 def underscore_to_hyphen(data):
847 new_data = None
848 if isinstance(data, list):
849 new_data = []
850 for i, elem in enumerate(data):
851 new_data.append(underscore_to_hyphen(elem))
852 elif isinstance(data, dict):
853 new_data = {}
854 for k, v in data.items():
855 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
856 else:
857 return data
858 return new_data
859
860
861 def router_ospf6(data, fos, check_mode=False):
862
863 state = None
864 vdom = data["vdom"]
865 parameters = None
866 state = data.get("state", None)
867 router_ospf6_data = data["router_ospf6"]
868
869 filtered_data = filter_router_ospf6_data(router_ospf6_data)
870 converted_data = underscore_to_hyphen(filtered_data)
871
872 # check_mode starts from here
873 if check_mode:
874 diff = {
875 "before": "",
876 "after": filtered_data,
877 }
878 mkeyname = fos.get_mkeyname(None, None)
879 mkey = fos.get_mkey("router", "ospf6", filtered_data, vdom=vdom)
880 current_data = fos.get(
881 "router", "ospf6", vdom=vdom, mkey=mkey, parameters=parameters
882 )
883 is_existed = (
884 current_data
885 and current_data.get("http_status") == 200
886 and (
887 mkeyname
888 and isinstance(current_data.get("results"), list)
889 and len(current_data["results"]) > 0
890 or not mkeyname
891 and current_data["results"] # global object response
892 )
893 )
894
895 # 2. if it exists and the state is 'present' then compare current settings with desired
896 if state == "present" or state is True or state is None:
897 # for non global modules, mkeyname must exist and it's a new module when mkey is None
898 if mkeyname is not None and mkey is None:
899 return False, True, filtered_data, diff
900
901 # if mkey exists then compare each other
902 # record exits and they're matched or not
903 copied_filtered_data = filtered_data.copy()
904 copied_filtered_data.pop(mkeyname, None)
905 unified_filtered_data = unify_data_format(copied_filtered_data)
906
907 current_data_results = current_data.get("results", {})
908 current_config = (
909 current_data_results[0]
910 if mkeyname
911 and isinstance(current_data_results, list)
912 and len(current_data_results) > 0
913 else current_data_results
914 )
915 if is_existed:
916 unified_current_values = find_current_values(
917 unified_filtered_data,
918 unify_data_format(current_config),
919 )
920
921 is_same = is_same_comparison(
922 serialize(unified_current_values), serialize(unified_filtered_data)
923 )
924
925 return (
926 False,
927 not is_same,
928 filtered_data,
929 {"before": unified_current_values, "after": unified_filtered_data},
930 )
931
932 # record does not exist
933 return False, True, filtered_data, diff
934
935 if state == "absent":
936 if mkey is None:
937 return (
938 False,
939 False,
940 filtered_data,
941 {"before": current_data["results"][0], "after": ""},
942 )
943
944 if is_existed:
945 return (
946 False,
947 True,
948 filtered_data,
949 {"before": current_data["results"][0], "after": ""},
950 )
951 return False, False, filtered_data, {}
952
953 return True, False, {"reason: ": "Must provide state parameter"}, {}
954 # pass post processed data to member operations
955 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
956 data_copy = data.copy()
957 data_copy["router_ospf6"] = filtered_data
958 fos.do_member_operation(
959 "router",
960 "ospf6",
961 data_copy,
962 )
963
964 return fos.set(
965 "router", "ospf6", data=converted_data, vdom=vdom, parameters=parameters
966 )
967
968
969 def is_successful_status(resp):
970 return (
971 "status" in resp
972 and resp["status"] == "success"
973 or "http_status" in resp
974 and resp["http_status"] == 200
975 or "http_method" in resp
976 and resp["http_method"] == "DELETE"
977 and resp["http_status"] == 404
978 )
979
980
981 def fortios_router(data, fos, check_mode):
982
983 if data["router_ospf6"]:
984 resp = router_ospf6(data, fos, check_mode)
985 else:
986 fos._module.fail_json(msg="missing task body: %s" % ("router_ospf6"))
987 if isinstance(resp, tuple) and len(resp) == 4:
988 return resp
989 return (
990 not is_successful_status(resp),
991 is_successful_status(resp)
992 and (resp["revision_changed"] if "revision_changed" in resp else True),
993 resp,
994 {},
995 )
996
997
998 versioned_schema = {
999 "v_range": [["v6.0.0", ""]],
1000 "type": "dict",
1001 "children": {
1002 "abr_type": {
1003 "v_range": [["v6.0.0", ""]],
1004 "type": "string",
1005 "options": [{"value": "cisco"}, {"value": "ibm"}, {"value": "standard"}],
1006 },
1007 "auto_cost_ref_bandwidth": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1008 "default_information_originate": {
1009 "v_range": [["v6.0.0", ""]],
1010 "type": "string",
1011 "options": [{"value": "enable"}, {"value": "always"}, {"value": "disable"}],
1012 },
1013 "log_neighbour_changes": {
1014 "v_range": [["v6.0.0", ""]],
1015 "type": "string",
1016 "options": [{"value": "enable"}, {"value": "disable"}],
1017 },
1018 "default_information_metric": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1019 "default_information_metric_type": {
1020 "v_range": [["v6.0.0", ""]],
1021 "type": "string",
1022 "options": [{"value": "1"}, {"value": "2"}],
1023 },
1024 "default_information_route_map": {
1025 "v_range": [["v6.0.0", ""]],
1026 "type": "string",
1027 },
1028 "default_metric": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1029 "router_id": {"v_range": [["v6.0.0", ""]], "type": "string"},
1030 "spf_timers": {"v_range": [["v6.0.0", ""]], "type": "string"},
1031 "bfd": {
1032 "v_range": [["v6.0.0", ""]],
1033 "type": "string",
1034 "options": [{"value": "enable"}, {"value": "disable"}],
1035 },
1036 "restart_mode": {
1037 "v_range": [["v7.2.0", ""]],
1038 "type": "string",
1039 "options": [{"value": "none"}, {"value": "graceful-restart"}],
1040 },
1041 "restart_period": {"v_range": [["v7.2.0", ""]], "type": "integer"},
1042 "restart_on_topology_change": {
1043 "v_range": [["v7.2.0", ""]],
1044 "type": "string",
1045 "options": [{"value": "enable"}, {"value": "disable"}],
1046 },
1047 "area": {
1048 "type": "list",
1049 "elements": "dict",
1050 "children": {
1051 "id": {"v_range": [["v6.0.0", ""]], "type": "string", "required": True},
1052 "default_cost": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1053 "nssa_translator_role": {
1054 "v_range": [["v6.0.0", ""]],
1055 "type": "string",
1056 "options": [
1057 {"value": "candidate"},
1058 {"value": "never"},
1059 {"value": "always"},
1060 ],
1061 },
1062 "stub_type": {
1063 "v_range": [["v6.0.0", ""]],
1064 "type": "string",
1065 "options": [{"value": "no-summary"}, {"value": "summary"}],
1066 },
1067 "type": {
1068 "v_range": [["v6.0.0", ""]],
1069 "type": "string",
1070 "options": [
1071 {"value": "regular"},
1072 {"value": "nssa"},
1073 {"value": "stub"},
1074 ],
1075 },
1076 "nssa_default_information_originate": {
1077 "v_range": [["v6.0.0", ""]],
1078 "type": "string",
1079 "options": [{"value": "enable"}, {"value": "disable"}],
1080 },
1081 "nssa_default_information_originate_metric": {
1082 "v_range": [["v6.0.0", ""]],
1083 "type": "integer",
1084 },
1085 "nssa_default_information_originate_metric_type": {
1086 "v_range": [["v6.0.0", ""]],
1087 "type": "string",
1088 "options": [{"value": "1"}, {"value": "2"}],
1089 },
1090 "nssa_redistribution": {
1091 "v_range": [["v6.0.0", ""]],
1092 "type": "string",
1093 "options": [{"value": "enable"}, {"value": "disable"}],
1094 },
1095 "authentication": {
1096 "v_range": [["v6.2.0", ""]],
1097 "type": "string",
1098 "options": [{"value": "none"}, {"value": "ah"}, {"value": "esp"}],
1099 },
1100 "key_rollover_interval": {
1101 "v_range": [["v6.2.0", ""]],
1102 "type": "integer",
1103 },
1104 "ipsec_auth_alg": {
1105 "v_range": [["v6.2.0", ""]],
1106 "type": "string",
1107 "options": [
1108 {"value": "md5"},
1109 {"value": "sha1"},
1110 {"value": "sha256"},
1111 {"value": "sha384"},
1112 {"value": "sha512"},
1113 ],
1114 },
1115 "ipsec_enc_alg": {
1116 "v_range": [["v6.2.0", ""]],
1117 "type": "string",
1118 "options": [
1119 {"value": "null"},
1120 {"value": "des"},
1121 {"value": "3des"},
1122 {"value": "aes128"},
1123 {"value": "aes192"},
1124 {"value": "aes256"},
1125 ],
1126 },
1127 "ipsec_keys": {
1128 "type": "list",
1129 "elements": "dict",
1130 "children": {
1131 "spi": {
1132 "v_range": [["v6.2.0", ""]],
1133 "type": "integer",
1134 "required": True,
1135 },
1136 "auth_key": {"v_range": [["v6.2.0", ""]], "type": "string"},
1137 "enc_key": {"v_range": [["v6.2.0", ""]], "type": "string"},
1138 },
1139 "v_range": [["v6.2.0", ""]],
1140 },
1141 "range": {
1142 "type": "list",
1143 "elements": "dict",
1144 "children": {
1145 "id": {
1146 "v_range": [["v6.0.0", ""]],
1147 "type": "integer",
1148 "required": True,
1149 },
1150 "prefix6": {"v_range": [["v6.0.0", ""]], "type": "string"},
1151 "advertise": {
1152 "v_range": [["v6.0.0", ""]],
1153 "type": "string",
1154 "options": [{"value": "disable"}, {"value": "enable"}],
1155 },
1156 },
1157 "v_range": [["v6.0.0", ""]],
1158 },
1159 "virtual_link": {
1160 "type": "list",
1161 "elements": "dict",
1162 "children": {
1163 "name": {
1164 "v_range": [["v6.0.0", ""]],
1165 "type": "string",
1166 "required": True,
1167 },
1168 "dead_interval": {
1169 "v_range": [["v6.0.0", ""]],
1170 "type": "integer",
1171 },
1172 "hello_interval": {
1173 "v_range": [["v6.0.0", ""]],
1174 "type": "integer",
1175 },
1176 "retransmit_interval": {
1177 "v_range": [["v6.0.0", ""]],
1178 "type": "integer",
1179 },
1180 "transmit_delay": {
1181 "v_range": [["v6.0.0", ""]],
1182 "type": "integer",
1183 },
1184 "peer": {"v_range": [["v6.0.0", ""]], "type": "string"},
1185 "authentication": {
1186 "v_range": [["v6.2.0", ""]],
1187 "type": "string",
1188 "options": [
1189 {"value": "none"},
1190 {"value": "ah"},
1191 {"value": "esp"},
1192 {"value": "area"},
1193 ],
1194 },
1195 "key_rollover_interval": {
1196 "v_range": [["v6.2.0", ""]],
1197 "type": "integer",
1198 },
1199 "ipsec_auth_alg": {
1200 "v_range": [["v6.2.0", ""]],
1201 "type": "string",
1202 "options": [
1203 {"value": "md5"},
1204 {"value": "sha1"},
1205 {"value": "sha256"},
1206 {"value": "sha384"},
1207 {"value": "sha512"},
1208 ],
1209 },
1210 "ipsec_enc_alg": {
1211 "v_range": [["v6.2.0", ""]],
1212 "type": "string",
1213 "options": [
1214 {"value": "null"},
1215 {"value": "des"},
1216 {"value": "3des"},
1217 {"value": "aes128"},
1218 {"value": "aes192"},
1219 {"value": "aes256"},
1220 ],
1221 },
1222 "ipsec_keys": {
1223 "type": "list",
1224 "elements": "dict",
1225 "children": {
1226 "spi": {
1227 "v_range": [["v6.2.0", ""]],
1228 "type": "integer",
1229 "required": True,
1230 },
1231 "auth_key": {
1232 "v_range": [["v6.2.0", ""]],
1233 "type": "string",
1234 },
1235 "enc_key": {
1236 "v_range": [["v6.2.0", ""]],
1237 "type": "string",
1238 },
1239 },
1240 "v_range": [["v6.2.0", ""]],
1241 },
1242 },
1243 "v_range": [["v6.0.0", ""]],
1244 },
1245 },
1246 "v_range": [["v6.0.0", ""]],
1247 },
1248 "ospf6_interface": {
1249 "type": "list",
1250 "elements": "dict",
1251 "children": {
1252 "name": {
1253 "v_range": [["v6.0.0", ""]],
1254 "type": "string",
1255 "required": True,
1256 },
1257 "area_id": {"v_range": [["v6.0.0", ""]], "type": "string"},
1258 "interface": {"v_range": [["v6.0.0", ""]], "type": "string"},
1259 "retransmit_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1260 "transmit_delay": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1261 "cost": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1262 "priority": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1263 "dead_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1264 "hello_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1265 "status": {
1266 "v_range": [["v6.0.0", ""]],
1267 "type": "string",
1268 "options": [{"value": "disable"}, {"value": "enable"}],
1269 },
1270 "network_type": {
1271 "v_range": [["v6.0.0", ""]],
1272 "type": "string",
1273 "options": [
1274 {"value": "broadcast"},
1275 {"value": "point-to-point"},
1276 {"value": "non-broadcast"},
1277 {"value": "point-to-multipoint"},
1278 {"value": "point-to-multipoint-non-broadcast"},
1279 ],
1280 },
1281 "bfd": {
1282 "v_range": [["v6.0.0", ""]],
1283 "type": "string",
1284 "options": [
1285 {"value": "global"},
1286 {"value": "enable"},
1287 {"value": "disable"},
1288 ],
1289 },
1290 "mtu": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1291 "mtu_ignore": {
1292 "v_range": [["v6.0.0", ""]],
1293 "type": "string",
1294 "options": [{"value": "enable"}, {"value": "disable"}],
1295 },
1296 "authentication": {
1297 "v_range": [["v6.2.0", ""]],
1298 "type": "string",
1299 "options": [
1300 {"value": "none"},
1301 {"value": "ah"},
1302 {"value": "esp"},
1303 {"value": "area"},
1304 ],
1305 },
1306 "key_rollover_interval": {
1307 "v_range": [["v6.2.0", ""]],
1308 "type": "integer",
1309 },
1310 "ipsec_auth_alg": {
1311 "v_range": [["v6.2.0", ""]],
1312 "type": "string",
1313 "options": [
1314 {"value": "md5"},
1315 {"value": "sha1"},
1316 {"value": "sha256"},
1317 {"value": "sha384"},
1318 {"value": "sha512"},
1319 ],
1320 },
1321 "ipsec_enc_alg": {
1322 "v_range": [["v6.2.0", ""]],
1323 "type": "string",
1324 "options": [
1325 {"value": "null"},
1326 {"value": "des"},
1327 {"value": "3des"},
1328 {"value": "aes128"},
1329 {"value": "aes192"},
1330 {"value": "aes256"},
1331 ],
1332 },
1333 "ipsec_keys": {
1334 "type": "list",
1335 "elements": "dict",
1336 "children": {
1337 "spi": {
1338 "v_range": [["v6.2.0", ""]],
1339 "type": "integer",
1340 "required": True,
1341 },
1342 "auth_key": {"v_range": [["v6.2.0", ""]], "type": "string"},
1343 "enc_key": {"v_range": [["v6.2.0", ""]], "type": "string"},
1344 },
1345 "v_range": [["v6.2.0", ""]],
1346 },
1347 "neighbor": {
1348 "type": "list",
1349 "elements": "dict",
1350 "children": {
1351 "ip6": {
1352 "v_range": [["v6.0.0", ""]],
1353 "type": "string",
1354 "required": True,
1355 },
1356 "poll_interval": {
1357 "v_range": [["v6.0.0", ""]],
1358 "type": "integer",
1359 },
1360 "cost": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1361 "priority": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1362 },
1363 "v_range": [["v6.0.0", ""]],
1364 },
1365 },
1366 "v_range": [["v6.0.0", ""]],
1367 },
1368 "passive_interface": {
1369 "type": "list",
1370 "elements": "dict",
1371 "children": {
1372 "name": {
1373 "v_range": [["v6.0.0", ""]],
1374 "type": "string",
1375 "required": True,
1376 }
1377 },
1378 "v_range": [["v6.0.0", ""]],
1379 },
1380 "summary_address": {
1381 "type": "list",
1382 "elements": "dict",
1383 "children": {
1384 "id": {
1385 "v_range": [["v6.0.0", ""]],
1386 "type": "integer",
1387 "required": True,
1388 },
1389 "prefix6": {"v_range": [["v6.0.0", ""]], "type": "string"},
1390 "advertise": {
1391 "v_range": [["v6.0.0", ""]],
1392 "type": "string",
1393 "options": [{"value": "disable"}, {"value": "enable"}],
1394 },
1395 "tag": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1396 },
1397 "v_range": [["v6.0.0", ""]],
1398 },
1399 "redistribute": {
1400 "type": "list",
1401 "elements": "dict",
1402 "children": {
1403 "name": {
1404 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1405 "type": "string",
1406 "required": True,
1407 },
1408 "status": {
1409 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1410 "type": "string",
1411 "options": [{"value": "enable"}, {"value": "disable"}],
1412 },
1413 "metric": {
1414 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1415 "type": "integer",
1416 },
1417 "routemap": {
1418 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1419 "type": "string",
1420 },
1421 "metric_type": {
1422 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1423 "type": "string",
1424 "options": [{"value": "1"}, {"value": "2"}],
1425 },
1426 },
1427 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1428 },
1429 },
1430 }
1431
1432
1433 def main():
1434 module_spec = schema_to_module_spec(versioned_schema)
1435 mkeyname = None
1436 fields = {
1437 "access_token": {"required": False, "type": "str", "no_log": True},
1438 "enable_log": {"required": False, "type": "bool", "default": False},
1439 "vdom": {"required": False, "type": "str", "default": "root"},
1440 "member_path": {"required": False, "type": "str"},
1441 "member_state": {
1442 "type": "str",
1443 "required": False,
1444 "choices": ["present", "absent"],
1445 },
1446 "router_ospf6": {
1447 "required": False,
1448 "type": "dict",
1449 "default": None,
1450 "options": {},
1451 },
1452 }
1453 for attribute_name in module_spec["options"]:
1454 fields["router_ospf6"]["options"][attribute_name] = module_spec["options"][
1455 attribute_name
1456 ]
1457 if mkeyname and mkeyname == attribute_name:
1458 fields["router_ospf6"]["options"][attribute_name]["required"] = True
1459
1460 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
1461 check_legacy_fortiosapi(module)
1462
1463 is_error = False
1464 has_changed = False
1465 result = None
1466 diff = None
1467
1468 versions_check_result = None
1469 if module._socket_path:
1470 connection = Connection(module._socket_path)
1471 if "access_token" in module.params:
1472 connection.set_custom_option("access_token", module.params["access_token"])
1473
1474 if "enable_log" in module.params:
1475 connection.set_custom_option("enable_log", module.params["enable_log"])
1476 else:
1477 connection.set_custom_option("enable_log", False)
1478 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
1479 versions_check_result = check_schema_versioning(
1480 fos, versioned_schema, "router_ospf6"
1481 )
1482
1483 is_error, has_changed, result, diff = fortios_router(
1484 module.params, fos, module.check_mode
1485 )
1486
1487 else:
1488 module.fail_json(**FAIL_SOCKET_MSG)
1489
1490 if versions_check_result and versions_check_result["matched"] is False:
1491 module.warn(
1492 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
1493 )
1494
1495 if not is_error:
1496 if versions_check_result and versions_check_result["matched"] is False:
1497 module.exit_json(
1498 changed=has_changed,
1499 version_check_warning=versions_check_result,
1500 meta=result,
1501 diff=diff,
1502 )
1503 else:
1504 module.exit_json(changed=has_changed, meta=result, diff=diff)
1505 else:
1506 if versions_check_result and versions_check_result["matched"] is False:
1507 module.fail_json(
1508 msg="Error in repo",
1509 version_check_warning=versions_check_result,
1510 meta=result,
1511 )
1512 else:
1513 module.fail_json(msg="Error in repo", meta=result)
1514
1515
1516 if __name__ == "__main__":
1517 main()