Debian Codegraph @

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