Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_router_rip.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_rip
23 short_description: Configure RIP 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 rip 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_rip:
80 description:
81 - Configure RIP.
82 default: null
83 type: dict
84 suboptions:
85 default_information_originate:
86 description:
87 - Enable/disable generation of default route.
88 type: str
89 choices:
90 - 'enable'
91 - 'disable'
92 default_metric:
93 description:
94 - Default metric.
95 type: int
96 distance:
97 description:
98 - Distance.
99 type: list
100 elements: dict
101 suboptions:
102 access_list:
103 description:
104 - Access list for route destination. Source router.access-list.name.
105 type: str
106 distance:
107 description:
108 - Distance (1 - 255).
109 type: int
110 id:
111 description:
112 - Distance ID. see <a href='#notes'>Notes</a>.
113 required: true
114 type: int
115 prefix:
116 description:
117 - Distance prefix.
118 type: str
119 distribute_list:
120 description:
121 - Distribute list.
122 type: list
123 elements: dict
124 suboptions:
125 direction:
126 description:
127 - Distribute list direction.
128 type: str
129 choices:
130 - 'in'
131 - 'out'
132 id:
133 description:
134 - Distribute list ID. see <a href='#notes'>Notes</a>.
135 required: true
136 type: int
137 interface:
138 description:
139 - Distribute list interface name. Source system.interface.name.
140 type: str
141 listname:
142 description:
143 - Distribute access/prefix list name. Source router.access-list.name router.prefix-list.name.
144 type: str
145 status:
146 description:
147 - Status.
148 type: str
149 choices:
150 - 'enable'
151 - 'disable'
152 garbage_timer:
153 description:
154 - Garbage timer in seconds.
155 type: int
156 interface:
157 description:
158 - RIP interface configuration.
159 type: list
160 elements: dict
161 suboptions:
162 auth_keychain:
163 description:
164 - Authentication key-chain name. Source router.key-chain.name.
165 type: str
166 auth_mode:
167 description:
168 - Authentication mode.
169 type: str
170 choices:
171 - 'none'
172 - 'text'
173 - 'md5'
174 auth_string:
175 description:
176 - Authentication string/password.
177 type: str
178 flags:
179 description:
180 - Flags.
181 type: int
182 name:
183 description:
184 - Interface name. Source system.interface.name.
185 required: true
186 type: str
187 receive_version:
188 description:
189 - Receive version.
190 type: list
191 elements: str
192 choices:
193 - '1'
194 - '2'
195 send_version:
196 description:
197 - Send version.
198 type: list
199 elements: str
200 choices:
201 - '1'
202 - '2'
203 send_version2_broadcast:
204 description:
205 - Enable/disable broadcast version 1 compatible packets.
206 type: str
207 choices:
208 - 'disable'
209 - 'enable'
210 split_horizon:
211 description:
212 - Enable/disable split horizon.
213 type: str
214 choices:
215 - 'poisoned'
216 - 'regular'
217 split_horizon_status:
218 description:
219 - Enable/disable split horizon.
220 type: str
221 choices:
222 - 'enable'
223 - 'disable'
224 max_out_metric:
225 description:
226 - Maximum metric allowed to output(0 means "not set").
227 type: int
228 neighbor:
229 description:
230 - Neighbor.
231 type: list
232 elements: dict
233 suboptions:
234 id:
235 description:
236 - Neighbor entry ID. see <a href='#notes'>Notes</a>.
237 required: true
238 type: int
239 ip:
240 description:
241 - IP address.
242 type: str
243 network:
244 description:
245 - Network.
246 type: list
247 elements: dict
248 suboptions:
249 id:
250 description:
251 - Network entry ID. see <a href='#notes'>Notes</a>.
252 required: true
253 type: int
254 prefix:
255 description:
256 - Network prefix.
257 type: str
258 offset_list:
259 description:
260 - Offset list.
261 type: list
262 elements: dict
263 suboptions:
264 access_list:
265 description:
266 - Access list name. Source router.access-list.name.
267 type: str
268 direction:
269 description:
270 - Offset list direction.
271 type: str
272 choices:
273 - 'in'
274 - 'out'
275 id:
276 description:
277 - Offset-list ID. see <a href='#notes'>Notes</a>.
278 required: true
279 type: int
280 interface:
281 description:
282 - Interface name. Source system.interface.name.
283 type: str
284 offset:
285 description:
286 - Offset.
287 type: int
288 status:
289 description:
290 - Status.
291 type: str
292 choices:
293 - 'enable'
294 - 'disable'
295 passive_interface:
296 description:
297 - Passive interface configuration.
298 type: list
299 elements: dict
300 suboptions:
301 name:
302 description:
303 - Passive interface name. Source system.interface.name.
304 required: true
305 type: str
306 recv_buffer_size:
307 description:
308 - Receiving buffer size.
309 type: int
310 redistribute:
311 description:
312 - Redistribute configuration.
313 type: list
314 elements: dict
315 suboptions:
316 metric:
317 description:
318 - Redistribute metric setting.
319 type: int
320 name:
321 description:
322 - Redistribute name.
323 required: true
324 type: str
325 routemap:
326 description:
327 - Route map name. Source router.route-map.name.
328 type: str
329 status:
330 description:
331 - Status.
332 type: str
333 choices:
334 - 'enable'
335 - 'disable'
336 timeout_timer:
337 description:
338 - Timeout timer in seconds.
339 type: int
340 update_timer:
341 description:
342 - Update timer in seconds.
343 type: int
344 version:
345 description:
346 - RIP version.
347 type: str
348 choices:
349 - '1'
350 - '2'
351 """
352
353 EXAMPLES = """
354 - name: Configure RIP.
355 fortinet.fortios.fortios_router_rip:
356 vdom: "{{ vdom }}"
357 router_rip:
358 default_information_originate: "enable"
359 default_metric: "1"
360 distance:
361 -
362 access_list: "<your_own_value> (source router.access-list.name)"
363 distance: "0"
364 id: "8"
365 prefix: "<your_own_value>"
366 distribute_list:
367 -
368 direction: "in"
369 id: "12"
370 interface: "<your_own_value> (source system.interface.name)"
371 listname: "<your_own_value> (source router.access-list.name router.prefix-list.name)"
372 status: "enable"
373 garbage_timer: "120"
374 interface:
375 -
376 auth_keychain: "<your_own_value> (source router.key-chain.name)"
377 auth_mode: "none"
378 auth_string: "<your_own_value>"
379 flags: "8"
380 name: "default_name_22 (source system.interface.name)"
381 receive_version: "1"
382 send_version: "1"
383 send_version2_broadcast: "disable"
384 split_horizon: "poisoned"
385 split_horizon_status: "enable"
386 max_out_metric: "0"
387 neighbor:
388 -
389 id: "30"
390 ip: "<your_own_value>"
391 network:
392 -
393 id: "33"
394 prefix: "<your_own_value>"
395 offset_list:
396 -
397 access_list: "<your_own_value> (source router.access-list.name)"
398 direction: "in"
399 id: "38"
400 interface: "<your_own_value> (source system.interface.name)"
401 offset: "0"
402 status: "enable"
403 passive_interface:
404 -
405 name: "default_name_43 (source system.interface.name)"
406 recv_buffer_size: "655360"
407 redistribute:
408 -
409 metric: "0"
410 name: "default_name_47"
411 routemap: "<your_own_value> (source router.route-map.name)"
412 status: "enable"
413 timeout_timer: "180"
414 update_timer: "30"
415 version: "1"
416 """
417
418 RETURN = """
419 build:
420 description: Build number of the fortigate image
421 returned: always
422 type: str
423 sample: '1547'
424 http_method:
425 description: Last method used to provision the content into FortiGate
426 returned: always
427 type: str
428 sample: 'PUT'
429 http_status:
430 description: Last result given by FortiGate on last operation applied
431 returned: always
432 type: str
433 sample: "200"
434 mkey:
435 description: Master key (id) used in the last call to FortiGate
436 returned: success
437 type: str
438 sample: "id"
439 name:
440 description: Name of the table used to fulfill the request
441 returned: always
442 type: str
443 sample: "urlfilter"
444 path:
445 description: Path of the table used to fulfill the request
446 returned: always
447 type: str
448 sample: "webfilter"
449 revision:
450 description: Internal revision number
451 returned: always
452 type: str
453 sample: "17.0.2.10658"
454 serial:
455 description: Serial number of the unit
456 returned: always
457 type: str
458 sample: "FGVMEVYYQT3AB5352"
459 status:
460 description: Indication of the operation's result
461 returned: always
462 type: str
463 sample: "success"
464 vdom:
465 description: Virtual domain used
466 returned: always
467 type: str
468 sample: "root"
469 version:
470 description: Version of the FortiGate
471 returned: always
472 type: str
473 sample: "v5.6.3"
474 """
475 from ansible.module_utils.basic import AnsibleModule
476 from ansible.module_utils.connection import Connection
477 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
478 FortiOSHandler,
479 )
480 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
481 check_legacy_fortiosapi,
482 )
483 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
484 schema_to_module_spec,
485 )
486 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
487 check_schema_versioning,
488 )
489 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
490 FAIL_SOCKET_MSG,
491 )
492 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
493 remove_invalid_fields,
494 )
495 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
496 is_same_comparison,
497 )
498 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
499 serialize,
500 )
501 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
502 find_current_values,
503 )
504 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
505 unify_data_format,
506 )
507
508
509 def filter_router_rip_data(json):
510 option_list = [
511 "default_information_originate",
512 "default_metric",
513 "distance",
514 "distribute_list",
515 "garbage_timer",
516 "interface",
517 "max_out_metric",
518 "neighbor",
519 "network",
520 "offset_list",
521 "passive_interface",
522 "recv_buffer_size",
523 "redistribute",
524 "timeout_timer",
525 "update_timer",
526 "version",
527 ]
528
529 json = remove_invalid_fields(json)
530 dictionary = {}
531
532 for attribute in option_list:
533 if attribute in json and json[attribute] is not None:
534 dictionary[attribute] = json[attribute]
535
536 return dictionary
537
538
539 def flatten_single_path(data, path, index):
540 if (
541 not data
542 or index == len(path)
543 or path[index] not in data
544 or (not data[path[index]] and not isinstance(data[path[index]], list))
545 ):
546 return
547
548 if index == len(path) - 1:
549 data[path[index]] = " ".join(str(elem) for elem in data[path[index]])
550 if len(data[path[index]]) == 0:
551 data[path[index]] = None
552 elif isinstance(data[path[index]], list):
553 for value in data[path[index]]:
554 flatten_single_path(value, path, index + 1)
555 else:
556 flatten_single_path(data[path[index]], path, index + 1)
557
558
559 def flatten_multilists_attributes(data):
560 multilist_attrs = [
561 ["interface", "receive_version"],
562 ["interface", "send_version"],
563 ]
564
565 for attr in multilist_attrs:
566 flatten_single_path(data, attr, 0)
567
568 return data
569
570
571 def underscore_to_hyphen(data):
572 new_data = None
573 if isinstance(data, list):
574 new_data = []
575 for i, elem in enumerate(data):
576 new_data.append(underscore_to_hyphen(elem))
577 elif isinstance(data, dict):
578 new_data = {}
579 for k, v in data.items():
580 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
581 else:
582 return data
583 return new_data
584
585
586 def router_rip(data, fos, check_mode=False):
587
588 state = None
589 vdom = data["vdom"]
590 parameters = None
591 state = data.get("state", None)
592 router_rip_data = data["router_rip"]
593
594 filtered_data = filter_router_rip_data(router_rip_data)
595 filtered_data = flatten_multilists_attributes(filtered_data)
596 converted_data = underscore_to_hyphen(filtered_data)
597
598 # check_mode starts from here
599 if check_mode:
600 diff = {
601 "before": "",
602 "after": filtered_data,
603 }
604 mkeyname = fos.get_mkeyname(None, None)
605 mkey = fos.get_mkey("router", "rip", filtered_data, vdom=vdom)
606 current_data = fos.get(
607 "router", "rip", vdom=vdom, mkey=mkey, parameters=parameters
608 )
609 is_existed = (
610 current_data
611 and current_data.get("http_status") == 200
612 and (
613 mkeyname
614 and isinstance(current_data.get("results"), list)
615 and len(current_data["results"]) > 0
616 or not mkeyname
617 and current_data["results"] # global object response
618 )
619 )
620
621 # 2. if it exists and the state is 'present' then compare current settings with desired
622 if state == "present" or state is True or state is None:
623 # for non global modules, mkeyname must exist and it's a new module when mkey is None
624 if mkeyname is not None and mkey is None:
625 return False, True, filtered_data, diff
626
627 # if mkey exists then compare each other
628 # record exits and they're matched or not
629 copied_filtered_data = filtered_data.copy()
630 copied_filtered_data.pop(mkeyname, None)
631 unified_filtered_data = unify_data_format(copied_filtered_data)
632
633 current_data_results = current_data.get("results", {})
634 current_config = (
635 current_data_results[0]
636 if mkeyname
637 and isinstance(current_data_results, list)
638 and len(current_data_results) > 0
639 else current_data_results
640 )
641 if is_existed:
642 unified_current_values = find_current_values(
643 unified_filtered_data,
644 unify_data_format(current_config),
645 )
646
647 is_same = is_same_comparison(
648 serialize(unified_current_values), serialize(unified_filtered_data)
649 )
650
651 return (
652 False,
653 not is_same,
654 filtered_data,
655 {"before": unified_current_values, "after": unified_filtered_data},
656 )
657
658 # record does not exist
659 return False, True, filtered_data, diff
660
661 if state == "absent":
662 if mkey is None:
663 return (
664 False,
665 False,
666 filtered_data,
667 {"before": current_data["results"][0], "after": ""},
668 )
669
670 if is_existed:
671 return (
672 False,
673 True,
674 filtered_data,
675 {"before": current_data["results"][0], "after": ""},
676 )
677 return False, False, filtered_data, {}
678
679 return True, False, {"reason: ": "Must provide state parameter"}, {}
680 # pass post processed data to member operations
681 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
682 data_copy = data.copy()
683 data_copy["router_rip"] = filtered_data
684 fos.do_member_operation(
685 "router",
686 "rip",
687 data_copy,
688 )
689
690 return fos.set(
691 "router", "rip", data=converted_data, vdom=vdom, parameters=parameters
692 )
693
694
695 def is_successful_status(resp):
696 return (
697 "status" in resp
698 and resp["status"] == "success"
699 or "http_status" in resp
700 and resp["http_status"] == 200
701 or "http_method" in resp
702 and resp["http_method"] == "DELETE"
703 and resp["http_status"] == 404
704 )
705
706
707 def fortios_router(data, fos, check_mode):
708
709 if data["router_rip"]:
710 resp = router_rip(data, fos, check_mode)
711 else:
712 fos._module.fail_json(msg="missing task body: %s" % ("router_rip"))
713 if isinstance(resp, tuple) and len(resp) == 4:
714 return resp
715 return (
716 not is_successful_status(resp),
717 is_successful_status(resp)
718 and (resp["revision_changed"] if "revision_changed" in resp else True),
719 resp,
720 {},
721 )
722
723
724 versioned_schema = {
725 "v_range": [["v6.0.0", ""]],
726 "type": "dict",
727 "children": {
728 "default_information_originate": {
729 "v_range": [["v6.0.0", ""]],
730 "type": "string",
731 "options": [{"value": "enable"}, {"value": "disable"}],
732 },
733 "default_metric": {"v_range": [["v6.0.0", ""]], "type": "integer"},
734 "max_out_metric": {"v_range": [["v6.0.0", ""]], "type": "integer"},
735 "distance": {
736 "type": "list",
737 "elements": "dict",
738 "children": {
739 "id": {
740 "v_range": [["v6.0.0", ""]],
741 "type": "integer",
742 "required": True,
743 },
744 "prefix": {"v_range": [["v6.0.0", ""]], "type": "string"},
745 "distance": {"v_range": [["v6.0.0", ""]], "type": "integer"},
746 "access_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
747 },
748 "v_range": [["v6.0.0", ""]],
749 },
750 "distribute_list": {
751 "type": "list",
752 "elements": "dict",
753 "children": {
754 "id": {
755 "v_range": [["v6.0.0", ""]],
756 "type": "integer",
757 "required": True,
758 },
759 "status": {
760 "v_range": [["v6.0.0", ""]],
761 "type": "string",
762 "options": [{"value": "enable"}, {"value": "disable"}],
763 },
764 "direction": {
765 "v_range": [["v6.0.0", ""]],
766 "type": "string",
767 "options": [{"value": "in"}, {"value": "out"}],
768 },
769 "listname": {"v_range": [["v6.0.0", ""]], "type": "string"},
770 "interface": {"v_range": [["v6.0.0", ""]], "type": "string"},
771 },
772 "v_range": [["v6.0.0", ""]],
773 },
774 "neighbor": {
775 "type": "list",
776 "elements": "dict",
777 "children": {
778 "id": {
779 "v_range": [["v6.0.0", ""]],
780 "type": "integer",
781 "required": True,
782 },
783 "ip": {"v_range": [["v6.0.0", ""]], "type": "string"},
784 },
785 "v_range": [["v6.0.0", ""]],
786 },
787 "network": {
788 "type": "list",
789 "elements": "dict",
790 "children": {
791 "id": {
792 "v_range": [["v6.0.0", ""]],
793 "type": "integer",
794 "required": True,
795 },
796 "prefix": {"v_range": [["v6.0.0", ""]], "type": "string"},
797 },
798 "v_range": [["v6.0.0", ""]],
799 },
800 "offset_list": {
801 "type": "list",
802 "elements": "dict",
803 "children": {
804 "id": {
805 "v_range": [["v6.0.0", ""]],
806 "type": "integer",
807 "required": True,
808 },
809 "status": {
810 "v_range": [["v6.0.0", ""]],
811 "type": "string",
812 "options": [{"value": "enable"}, {"value": "disable"}],
813 },
814 "direction": {
815 "v_range": [["v6.0.0", ""]],
816 "type": "string",
817 "options": [{"value": "in"}, {"value": "out"}],
818 },
819 "access_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
820 "offset": {"v_range": [["v6.0.0", ""]], "type": "integer"},
821 "interface": {"v_range": [["v6.0.0", ""]], "type": "string"},
822 },
823 "v_range": [["v6.0.0", ""]],
824 },
825 "passive_interface": {
826 "type": "list",
827 "elements": "dict",
828 "children": {
829 "name": {
830 "v_range": [["v6.0.0", ""]],
831 "type": "string",
832 "required": True,
833 }
834 },
835 "v_range": [["v6.0.0", ""]],
836 },
837 "update_timer": {"v_range": [["v6.0.0", ""]], "type": "integer"},
838 "timeout_timer": {"v_range": [["v6.0.0", ""]], "type": "integer"},
839 "garbage_timer": {"v_range": [["v6.0.0", ""]], "type": "integer"},
840 "version": {
841 "v_range": [["v6.0.0", ""]],
842 "type": "string",
843 "options": [{"value": "1"}, {"value": "2"}],
844 },
845 "interface": {
846 "type": "list",
847 "elements": "dict",
848 "children": {
849 "name": {
850 "v_range": [["v6.0.0", ""]],
851 "type": "string",
852 "required": True,
853 },
854 "auth_keychain": {"v_range": [["v6.0.0", ""]], "type": "string"},
855 "auth_mode": {
856 "v_range": [["v6.0.0", ""]],
857 "type": "string",
858 "options": [{"value": "none"}, {"value": "text"}, {"value": "md5"}],
859 },
860 "auth_string": {"v_range": [["v6.0.0", ""]], "type": "string"},
861 "receive_version": {
862 "v_range": [["v6.0.0", ""]],
863 "type": "list",
864 "options": [{"value": "1"}, {"value": "2"}],
865 "multiple_values": True,
866 "elements": "str",
867 },
868 "send_version": {
869 "v_range": [["v6.0.0", ""]],
870 "type": "list",
871 "options": [{"value": "1"}, {"value": "2"}],
872 "multiple_values": True,
873 "elements": "str",
874 },
875 "send_version2_broadcast": {
876 "v_range": [["v6.0.0", ""]],
877 "type": "string",
878 "options": [{"value": "disable"}, {"value": "enable"}],
879 },
880 "split_horizon_status": {
881 "v_range": [["v6.0.0", ""]],
882 "type": "string",
883 "options": [{"value": "enable"}, {"value": "disable"}],
884 },
885 "split_horizon": {
886 "v_range": [["v6.0.0", ""]],
887 "type": "string",
888 "options": [{"value": "poisoned"}, {"value": "regular"}],
889 },
890 "flags": {
891 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
892 "type": "integer",
893 },
894 },
895 "v_range": [["v6.0.0", ""]],
896 },
897 "redistribute": {
898 "type": "list",
899 "elements": "dict",
900 "children": {
901 "name": {
902 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
903 "type": "string",
904 "required": True,
905 },
906 "status": {
907 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
908 "type": "string",
909 "options": [{"value": "enable"}, {"value": "disable"}],
910 },
911 "metric": {
912 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
913 "type": "integer",
914 },
915 "routemap": {
916 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
917 "type": "string",
918 },
919 },
920 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
921 },
922 "recv_buffer_size": {"v_range": [["v6.0.0", "v7.0.1"]], "type": "integer"},
923 },
924 }
925
926
927 def main():
928 module_spec = schema_to_module_spec(versioned_schema)
929 mkeyname = None
930 fields = {
931 "access_token": {"required": False, "type": "str", "no_log": True},
932 "enable_log": {"required": False, "type": "bool", "default": False},
933 "vdom": {"required": False, "type": "str", "default": "root"},
934 "member_path": {"required": False, "type": "str"},
935 "member_state": {
936 "type": "str",
937 "required": False,
938 "choices": ["present", "absent"],
939 },
940 "router_rip": {
941 "required": False,
942 "type": "dict",
943 "default": None,
944 "options": {},
945 },
946 }
947 for attribute_name in module_spec["options"]:
948 fields["router_rip"]["options"][attribute_name] = module_spec["options"][
949 attribute_name
950 ]
951 if mkeyname and mkeyname == attribute_name:
952 fields["router_rip"]["options"][attribute_name]["required"] = True
953
954 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
955 check_legacy_fortiosapi(module)
956
957 is_error = False
958 has_changed = False
959 result = None
960 diff = None
961
962 versions_check_result = None
963 if module._socket_path:
964 connection = Connection(module._socket_path)
965 if "access_token" in module.params:
966 connection.set_custom_option("access_token", module.params["access_token"])
967
968 if "enable_log" in module.params:
969 connection.set_custom_option("enable_log", module.params["enable_log"])
970 else:
971 connection.set_custom_option("enable_log", False)
972 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
973 versions_check_result = check_schema_versioning(
974 fos, versioned_schema, "router_rip"
975 )
976
977 is_error, has_changed, result, diff = fortios_router(
978 module.params, fos, module.check_mode
979 )
980
981 else:
982 module.fail_json(**FAIL_SOCKET_MSG)
983
984 if versions_check_result and versions_check_result["matched"] is False:
985 module.warn(
986 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
987 )
988
989 if not is_error:
990 if versions_check_result and versions_check_result["matched"] is False:
991 module.exit_json(
992 changed=has_changed,
993 version_check_warning=versions_check_result,
994 meta=result,
995 diff=diff,
996 )
997 else:
998 module.exit_json(changed=has_changed, meta=result, diff=diff)
999 else:
1000 if versions_check_result and versions_check_result["matched"] is False:
1001 module.fail_json(
1002 msg="Error in repo",
1003 version_check_warning=versions_check_result,
1004 meta=result,
1005 )
1006 else:
1007 module.fail_json(msg="Error in repo", meta=result)
1008
1009
1010 if __name__ == "__main__":
1011 main()