Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_vpn_ocvpn.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_vpn_ocvpn
23 short_description: Configure Overlay Controller VPN settings 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 vpn feature and ocvpn 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 vpn_ocvpn:
80 description:
81 - Configure Overlay Controller VPN settings.
82 default: null
83 type: dict
84 suboptions:
85 auto_discovery:
86 description:
87 - Enable/disable auto-discovery shortcuts.
88 type: str
89 choices:
90 - 'enable'
91 - 'disable'
92 auto_discovery_shortcut_mode:
93 description:
94 - Control deletion of child short-cut tunnels when the parent tunnel goes down.
95 type: str
96 choices:
97 - 'independent'
98 - 'dependent'
99 eap:
100 description:
101 - Enable/disable EAP client authentication.
102 type: str
103 choices:
104 - 'enable'
105 - 'disable'
106 eap_users:
107 description:
108 - EAP authentication user group. Source user.group.name.
109 type: str
110 forticlient_access:
111 description:
112 - Configure FortiClient settings.
113 type: dict
114 suboptions:
115 auth_groups:
116 description:
117 - FortiClient user authentication groups.
118 type: list
119 elements: dict
120 suboptions:
121 auth_group:
122 description:
123 - Authentication user group for FortiClient access. Source user.group.name.
124 type: str
125 name:
126 description:
127 - Group name.
128 required: true
129 type: str
130 overlays:
131 description:
132 - OCVPN overlays to allow access to.
133 type: list
134 elements: dict
135 suboptions:
136 overlay_name:
137 description:
138 - Overlay name. Source vpn.ocvpn.overlays.overlay-name.
139 required: true
140 type: str
141 psksecret:
142 description:
143 - Pre-shared secret for FortiClient PSK authentication (ASCII string or hexadecimal encoded with a leading 0x).
144 type: str
145 status:
146 description:
147 - Enable/disable FortiClient to access OCVPN networks.
148 type: str
149 choices:
150 - 'enable'
151 - 'disable'
152 ha_alias:
153 description:
154 - Hidden HA alias.
155 type: str
156 ip_allocation_block:
157 description:
158 - Class B subnet reserved for private IP address assignment.
159 type: str
160 multipath:
161 description:
162 - Enable/disable multipath redundancy.
163 type: str
164 choices:
165 - 'enable'
166 - 'disable'
167 nat:
168 description:
169 - Enable/disable NAT support.
170 type: str
171 choices:
172 - 'enable'
173 - 'disable'
174 overlays:
175 description:
176 - Network overlays to register with Overlay Controller VPN service.
177 type: list
178 elements: dict
179 suboptions:
180 assign_ip:
181 description:
182 - Enable/disable mode-cfg address assignment.
183 type: str
184 choices:
185 - 'enable'
186 - 'disable'
187 id:
188 description:
189 - ID.
190 type: int
191 inter_overlay:
192 description:
193 - Allow or deny traffic from other overlays.
194 type: str
195 choices:
196 - 'allow'
197 - 'deny'
198 ipv4_end_ip:
199 description:
200 - End of IPv4 range.
201 type: str
202 ipv4_start_ip:
203 description:
204 - Start of IPv4 range.
205 type: str
206 name:
207 description:
208 - Overlay name.
209 type: str
210 overlay_name:
211 description:
212 - Overlay name.
213 required: true
214 type: str
215 subnets:
216 description:
217 - Internal subnets to register with OCVPN service.
218 type: list
219 elements: dict
220 suboptions:
221 id:
222 description:
223 - ID. see <a href='#notes'>Notes</a>.
224 required: true
225 type: int
226 interface:
227 description:
228 - LAN interface. Source system.interface.name.
229 type: str
230 subnet:
231 description:
232 - IPv4 address and subnet mask.
233 type: str
234 type:
235 description:
236 - Subnet type.
237 type: str
238 choices:
239 - 'subnet'
240 - 'interface'
241 poll_interval:
242 description:
243 - Overlay Controller VPN polling interval.
244 type: int
245 role:
246 description:
247 - Set device role.
248 type: str
249 choices:
250 - 'spoke'
251 - 'primary-hub'
252 - 'secondary-hub'
253 sdwan:
254 description:
255 - Enable/disable adding OCVPN tunnels to SD-WAN.
256 type: str
257 choices:
258 - 'enable'
259 - 'disable'
260 sdwan_zone:
261 description:
262 - Set SD-WAN zone. Source system.sdwan.zone.name.
263 type: str
264 status:
265 description:
266 - Enable/disable Overlay Controller cloud assisted VPN.
267 type: str
268 choices:
269 - 'enable'
270 - 'disable'
271 subnets:
272 description:
273 - Internal subnets to register with Overlay Controller VPN service.
274 type: list
275 elements: dict
276 suboptions:
277 id:
278 description:
279 - ID. see <a href='#notes'>Notes</a>.
280 required: true
281 type: int
282 interface:
283 description:
284 - LAN interface. Source system.interface.name.
285 type: str
286 subnet:
287 description:
288 - IPv4 address and subnet mask.
289 type: str
290 type:
291 description:
292 - Subnet type.
293 type: str
294 choices:
295 - 'subnet'
296 - 'interface'
297 wan_interface:
298 description:
299 - FortiGate WAN interfaces to use with OCVPN.
300 type: list
301 elements: dict
302 suboptions:
303 name:
304 description:
305 - Interface name. Source system.interface.name.
306 required: true
307 type: str
308 """
309
310 EXAMPLES = """
311 - name: Configure Overlay Controller VPN settings.
312 fortinet.fortios.fortios_vpn_ocvpn:
313 vdom: "{{ vdom }}"
314 vpn_ocvpn:
315 auto_discovery: "enable"
316 auto_discovery_shortcut_mode: "independent"
317 eap: "enable"
318 eap_users: "<your_own_value> (source user.group.name)"
319 forticlient_access:
320 auth_groups:
321 -
322 auth_group: "<your_own_value> (source user.group.name)"
323 name: "default_name_10"
324 overlays:
325 -
326 overlay_name: "<your_own_value> (source vpn.ocvpn.overlays.overlay-name)"
327 psksecret: "<your_own_value>"
328 status: "enable"
329 ha_alias: "<your_own_value>"
330 ip_allocation_block: "<your_own_value>"
331 multipath: "enable"
332 nat: "enable"
333 overlays:
334 -
335 assign_ip: "enable"
336 id: "21"
337 inter_overlay: "allow"
338 ipv4_end_ip: "<your_own_value>"
339 ipv4_start_ip: "<your_own_value>"
340 name: "default_name_25"
341 overlay_name: "<your_own_value>"
342 subnets:
343 -
344 id: "28"
345 interface: "<your_own_value> (source system.interface.name)"
346 subnet: "<your_own_value>"
347 type: "subnet"
348 poll_interval: "30"
349 role: "spoke"
350 sdwan: "enable"
351 sdwan_zone: "<your_own_value> (source system.sdwan.zone.name)"
352 status: "enable"
353 subnets:
354 -
355 id: "38"
356 interface: "<your_own_value> (source system.interface.name)"
357 subnet: "<your_own_value>"
358 type: "subnet"
359 wan_interface:
360 -
361 name: "default_name_43 (source system.interface.name)"
362 """
363
364 RETURN = """
365 build:
366 description: Build number of the fortigate image
367 returned: always
368 type: str
369 sample: '1547'
370 http_method:
371 description: Last method used to provision the content into FortiGate
372 returned: always
373 type: str
374 sample: 'PUT'
375 http_status:
376 description: Last result given by FortiGate on last operation applied
377 returned: always
378 type: str
379 sample: "200"
380 mkey:
381 description: Master key (id) used in the last call to FortiGate
382 returned: success
383 type: str
384 sample: "id"
385 name:
386 description: Name of the table used to fulfill the request
387 returned: always
388 type: str
389 sample: "urlfilter"
390 path:
391 description: Path of the table used to fulfill the request
392 returned: always
393 type: str
394 sample: "webfilter"
395 revision:
396 description: Internal revision number
397 returned: always
398 type: str
399 sample: "17.0.2.10658"
400 serial:
401 description: Serial number of the unit
402 returned: always
403 type: str
404 sample: "FGVMEVYYQT3AB5352"
405 status:
406 description: Indication of the operation's result
407 returned: always
408 type: str
409 sample: "success"
410 vdom:
411 description: Virtual domain used
412 returned: always
413 type: str
414 sample: "root"
415 version:
416 description: Version of the FortiGate
417 returned: always
418 type: str
419 sample: "v5.6.3"
420 """
421 from ansible.module_utils.basic import AnsibleModule
422 from ansible.module_utils.connection import Connection
423 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
424 FortiOSHandler,
425 )
426 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
427 check_legacy_fortiosapi,
428 )
429 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
430 schema_to_module_spec,
431 )
432 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
433 check_schema_versioning,
434 )
435 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
436 FAIL_SOCKET_MSG,
437 )
438 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
439 remove_invalid_fields,
440 )
441 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
442 is_same_comparison,
443 )
444 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
445 serialize,
446 )
447 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
448 find_current_values,
449 )
450 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
451 unify_data_format,
452 )
453
454
455 def filter_vpn_ocvpn_data(json):
456 option_list = [
457 "auto_discovery",
458 "auto_discovery_shortcut_mode",
459 "eap",
460 "eap_users",
461 "forticlient_access",
462 "ha_alias",
463 "ip_allocation_block",
464 "multipath",
465 "nat",
466 "overlays",
467 "poll_interval",
468 "role",
469 "sdwan",
470 "sdwan_zone",
471 "status",
472 "subnets",
473 "wan_interface",
474 ]
475
476 json = remove_invalid_fields(json)
477 dictionary = {}
478
479 for attribute in option_list:
480 if attribute in json and json[attribute] is not None:
481 dictionary[attribute] = json[attribute]
482
483 return dictionary
484
485
486 def underscore_to_hyphen(data):
487 new_data = None
488 if isinstance(data, list):
489 new_data = []
490 for i, elem in enumerate(data):
491 new_data.append(underscore_to_hyphen(elem))
492 elif isinstance(data, dict):
493 new_data = {}
494 for k, v in data.items():
495 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
496 else:
497 return data
498 return new_data
499
500
501 def vpn_ocvpn(data, fos, check_mode=False):
502
503 state = None
504 vdom = data["vdom"]
505 parameters = None
506 state = data.get("state", None)
507 vpn_ocvpn_data = data["vpn_ocvpn"]
508
509 filtered_data = filter_vpn_ocvpn_data(vpn_ocvpn_data)
510 converted_data = underscore_to_hyphen(filtered_data)
511
512 # check_mode starts from here
513 if check_mode:
514 diff = {
515 "before": "",
516 "after": filtered_data,
517 }
518 mkeyname = fos.get_mkeyname(None, None)
519 mkey = fos.get_mkey("vpn", "ocvpn", filtered_data, vdom=vdom)
520 current_data = fos.get(
521 "vpn", "ocvpn", vdom=vdom, mkey=mkey, parameters=parameters
522 )
523 is_existed = (
524 current_data
525 and current_data.get("http_status") == 200
526 and (
527 mkeyname
528 and isinstance(current_data.get("results"), list)
529 and len(current_data["results"]) > 0
530 or not mkeyname
531 and current_data["results"] # global object response
532 )
533 )
534
535 # 2. if it exists and the state is 'present' then compare current settings with desired
536 if state == "present" or state is True or state is None:
537 # for non global modules, mkeyname must exist and it's a new module when mkey is None
538 if mkeyname is not None and mkey is None:
539 return False, True, filtered_data, diff
540
541 # if mkey exists then compare each other
542 # record exits and they're matched or not
543 copied_filtered_data = filtered_data.copy()
544 copied_filtered_data.pop(mkeyname, None)
545 unified_filtered_data = unify_data_format(copied_filtered_data)
546
547 current_data_results = current_data.get("results", {})
548 current_config = (
549 current_data_results[0]
550 if mkeyname
551 and isinstance(current_data_results, list)
552 and len(current_data_results) > 0
553 else current_data_results
554 )
555 if is_existed:
556 unified_current_values = find_current_values(
557 unified_filtered_data,
558 unify_data_format(current_config),
559 )
560
561 is_same = is_same_comparison(
562 serialize(unified_current_values), serialize(unified_filtered_data)
563 )
564
565 return (
566 False,
567 not is_same,
568 filtered_data,
569 {"before": unified_current_values, "after": unified_filtered_data},
570 )
571
572 # record does not exist
573 return False, True, filtered_data, diff
574
575 if state == "absent":
576 if mkey is None:
577 return (
578 False,
579 False,
580 filtered_data,
581 {"before": current_data["results"][0], "after": ""},
582 )
583
584 if is_existed:
585 return (
586 False,
587 True,
588 filtered_data,
589 {"before": current_data["results"][0], "after": ""},
590 )
591 return False, False, filtered_data, {}
592
593 return True, False, {"reason: ": "Must provide state parameter"}, {}
594 # pass post processed data to member operations
595 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
596 data_copy = data.copy()
597 data_copy["vpn_ocvpn"] = filtered_data
598 fos.do_member_operation(
599 "vpn",
600 "ocvpn",
601 data_copy,
602 )
603
604 return fos.set(
605 "vpn", "ocvpn", data=converted_data, vdom=vdom, parameters=parameters
606 )
607
608
609 def is_successful_status(resp):
610 return (
611 "status" in resp
612 and resp["status"] == "success"
613 or "http_status" in resp
614 and resp["http_status"] == 200
615 or "http_method" in resp
616 and resp["http_method"] == "DELETE"
617 and resp["http_status"] == 404
618 )
619
620
621 def fortios_vpn(data, fos, check_mode):
622
623 if data["vpn_ocvpn"]:
624 resp = vpn_ocvpn(data, fos, check_mode)
625 else:
626 fos._module.fail_json(msg="missing task body: %s" % ("vpn_ocvpn"))
627 if isinstance(resp, tuple) and len(resp) == 4:
628 return resp
629 return (
630 not is_successful_status(resp),
631 is_successful_status(resp)
632 and (resp["revision_changed"] if "revision_changed" in resp else True),
633 resp,
634 {},
635 )
636
637
638 versioned_schema = {
639 "v_range": [["v6.0.0", "v7.2.4"]],
640 "type": "dict",
641 "children": {
642 "status": {
643 "v_range": [["v6.0.0", "v7.2.4"]],
644 "type": "string",
645 "options": [{"value": "enable"}, {"value": "disable"}],
646 },
647 "role": {
648 "v_range": [["v6.2.0", "v7.2.4"]],
649 "type": "string",
650 "options": [
651 {"value": "spoke"},
652 {"value": "primary-hub"},
653 {"value": "secondary-hub"},
654 ],
655 },
656 "multipath": {
657 "v_range": [["v6.4.0", "v7.2.4"]],
658 "type": "string",
659 "options": [{"value": "enable"}, {"value": "disable"}],
660 },
661 "sdwan": {
662 "v_range": [["v6.4.0", "v7.2.4"]],
663 "type": "string",
664 "options": [{"value": "enable"}, {"value": "disable"}],
665 },
666 "sdwan_zone": {"v_range": [["v7.0.0", "v7.2.4"]], "type": "string"},
667 "wan_interface": {
668 "type": "list",
669 "elements": "dict",
670 "children": {
671 "name": {
672 "v_range": [["v6.4.0", "v7.2.4"]],
673 "type": "string",
674 "required": True,
675 }
676 },
677 "v_range": [["v6.4.0", "v7.2.4"]],
678 },
679 "nat": {
680 "v_range": [["v6.2.0", "v7.2.4"]],
681 "type": "string",
682 "options": [{"value": "enable"}, {"value": "disable"}],
683 },
684 "ip_allocation_block": {"v_range": [["v6.4.0", "v7.2.4"]], "type": "string"},
685 "overlays": {
686 "type": "list",
687 "elements": "dict",
688 "children": {
689 "overlay_name": {
690 "v_range": [["v6.4.0", "v7.2.4"]],
691 "type": "string",
692 "required": True,
693 },
694 "inter_overlay": {
695 "v_range": [["v6.4.0", "v7.2.4"]],
696 "type": "string",
697 "options": [{"value": "allow"}, {"value": "deny"}],
698 },
699 "subnets": {
700 "type": "list",
701 "elements": "dict",
702 "children": {
703 "id": {
704 "v_range": [["v6.2.0", "v7.2.4"]],
705 "type": "integer",
706 "required": True,
707 },
708 "type": {
709 "v_range": [["v6.2.0", "v7.2.4"]],
710 "type": "string",
711 "options": [{"value": "subnet"}, {"value": "interface"}],
712 },
713 "subnet": {"v_range": [["v6.2.0", "v7.2.4"]], "type": "string"},
714 "interface": {
715 "v_range": [["v6.2.0", "v7.2.4"]],
716 "type": "string",
717 },
718 },
719 "v_range": [["v6.2.0", "v7.2.4"]],
720 },
721 "assign_ip": {
722 "v_range": [["v6.2.0", "v7.0.0"]],
723 "type": "string",
724 "options": [{"value": "enable"}, {"value": "disable"}],
725 },
726 "ipv4_start_ip": {"v_range": [["v6.2.0", "v7.0.0"]], "type": "string"},
727 "ipv4_end_ip": {"v_range": [["v6.2.0", "v7.0.0"]], "type": "string"},
728 "id": {"v_range": [["v6.2.0", "v6.2.7"]], "type": "integer"},
729 "name": {"v_range": [["v6.2.0", "v6.2.7"]], "type": "string"},
730 },
731 "v_range": [["v6.2.0", "v7.2.4"]],
732 },
733 "forticlient_access": {
734 "v_range": [["v6.4.0", "v7.2.4"]],
735 "type": "dict",
736 "children": {
737 "status": {
738 "v_range": [["v6.4.0", "v7.2.4"]],
739 "type": "string",
740 "options": [{"value": "enable"}, {"value": "disable"}],
741 },
742 "psksecret": {"v_range": [["v6.4.0", "v7.2.4"]], "type": "string"},
743 "auth_groups": {
744 "type": "list",
745 "elements": "dict",
746 "children": {
747 "name": {
748 "v_range": [["v6.4.0", "v7.2.4"]],
749 "type": "string",
750 "required": True,
751 },
752 "auth_group": {
753 "v_range": [["v6.4.0", "v7.2.4"]],
754 "type": "string",
755 },
756 "overlays": {
757 "type": "list",
758 "elements": "dict",
759 "children": {
760 "overlay_name": {
761 "v_range": [["v6.4.0", "v7.2.4"]],
762 "type": "string",
763 "required": True,
764 }
765 },
766 "v_range": [["v6.4.0", "v7.2.4"]],
767 },
768 },
769 "v_range": [["v6.4.0", "v7.2.4"]],
770 },
771 },
772 },
773 "auto_discovery": {
774 "v_range": [["v6.2.0", "v7.2.4"]],
775 "type": "string",
776 "options": [{"value": "enable"}, {"value": "disable"}],
777 },
778 "auto_discovery_shortcut_mode": {
779 "v_range": [["v7.0.1", "v7.2.4"]],
780 "type": "string",
781 "options": [{"value": "independent"}, {"value": "dependent"}],
782 },
783 "poll_interval": {"v_range": [["v6.0.0", "v7.2.4"]], "type": "integer"},
784 "eap": {
785 "v_range": [["v6.2.0", "v7.2.4"]],
786 "type": "string",
787 "options": [{"value": "enable"}, {"value": "disable"}],
788 },
789 "eap_users": {"v_range": [["v6.2.0", "v7.2.4"]], "type": "string"},
790 "ha_alias": {
791 "v_range": [["v6.0.0", "v6.0.11"], ["v6.2.3", "v6.2.3"]],
792 "type": "string",
793 },
794 "subnets": {
795 "type": "list",
796 "elements": "dict",
797 "children": {
798 "id": {
799 "v_range": [["v6.0.0", "v6.0.11"]],
800 "type": "integer",
801 "required": True,
802 },
803 "type": {
804 "v_range": [["v6.0.0", "v6.0.11"]],
805 "type": "string",
806 "options": [{"value": "subnet"}, {"value": "interface"}],
807 },
808 "subnet": {"v_range": [["v6.0.0", "v6.0.11"]], "type": "string"},
809 "interface": {"v_range": [["v6.0.0", "v6.0.11"]], "type": "string"},
810 },
811 "v_range": [["v6.0.0", "v6.0.11"]],
812 },
813 },
814 }
815
816
817 def main():
818 module_spec = schema_to_module_spec(versioned_schema)
819 mkeyname = None
820 fields = {
821 "access_token": {"required": False, "type": "str", "no_log": True},
822 "enable_log": {"required": False, "type": "bool", "default": False},
823 "vdom": {"required": False, "type": "str", "default": "root"},
824 "member_path": {"required": False, "type": "str"},
825 "member_state": {
826 "type": "str",
827 "required": False,
828 "choices": ["present", "absent"],
829 },
830 "vpn_ocvpn": {
831 "required": False,
832 "type": "dict",
833 "default": None,
834 "options": {},
835 },
836 }
837 for attribute_name in module_spec["options"]:
838 fields["vpn_ocvpn"]["options"][attribute_name] = module_spec["options"][
839 attribute_name
840 ]
841 if mkeyname and mkeyname == attribute_name:
842 fields["vpn_ocvpn"]["options"][attribute_name]["required"] = True
843
844 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
845 check_legacy_fortiosapi(module)
846
847 is_error = False
848 has_changed = False
849 result = None
850 diff = None
851
852 versions_check_result = None
853 if module._socket_path:
854 connection = Connection(module._socket_path)
855 if "access_token" in module.params:
856 connection.set_custom_option("access_token", module.params["access_token"])
857
858 if "enable_log" in module.params:
859 connection.set_custom_option("enable_log", module.params["enable_log"])
860 else:
861 connection.set_custom_option("enable_log", False)
862 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
863 versions_check_result = check_schema_versioning(
864 fos, versioned_schema, "vpn_ocvpn"
865 )
866
867 is_error, has_changed, result, diff = fortios_vpn(
868 module.params, fos, module.check_mode
869 )
870
871 else:
872 module.fail_json(**FAIL_SOCKET_MSG)
873
874 if versions_check_result and versions_check_result["matched"] is False:
875 module.warn(
876 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
877 )
878
879 if not is_error:
880 if versions_check_result and versions_check_result["matched"] is False:
881 module.exit_json(
882 changed=has_changed,
883 version_check_warning=versions_check_result,
884 meta=result,
885 diff=diff,
886 )
887 else:
888 module.exit_json(changed=has_changed, meta=result, diff=diff)
889 else:
890 if versions_check_result and versions_check_result["matched"] is False:
891 module.fail_json(
892 msg="Error in repo",
893 version_check_warning=versions_check_result,
894 meta=result,
895 )
896 else:
897 module.fail_json(msg="Error in repo", meta=result)
898
899
900 if __name__ == "__main__":
901 main()