Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_wanopt_profile.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_wanopt_profile
23 short_description: Configure WAN optimization profiles 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 wanopt feature and profile 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 state:
80 description:
81 - Indicates whether to create or remove the object.
82 type: str
83 required: true
84 choices:
85 - 'present'
86 - 'absent'
87 wanopt_profile:
88 description:
89 - Configure WAN optimization profiles.
90 default: null
91 type: dict
92 suboptions:
93 auth_group:
94 description:
95 - Optionally add an authentication group to restrict access to the WAN Optimization tunnel to peers in the authentication group. Source
96 wanopt.auth-group.name.
97 type: str
98 cifs:
99 description:
100 - Enable/disable CIFS (Windows sharing) WAN Optimization and configure CIFS WAN Optimization features.
101 type: dict
102 suboptions:
103 byte_caching:
104 description:
105 - Enable/disable byte-caching. Byte caching reduces the amount of traffic by caching file data sent across the WAN and in future
106 serving if from the cache.
107 type: str
108 choices:
109 - 'enable'
110 - 'disable'
111 log_traffic:
112 description:
113 - Enable/disable logging.
114 type: str
115 choices:
116 - 'enable'
117 - 'disable'
118 port:
119 description:
120 - Single port number or port number range for CIFS. Only packets with a destination port number that matches this port number or
121 range are accepted by this profile.
122 type: int
123 prefer_chunking:
124 description:
125 - Select dynamic or fixed-size data chunking for WAN Optimization.
126 type: str
127 choices:
128 - 'dynamic'
129 - 'fix'
130 protocol_opt:
131 description:
132 - Select protocol specific optimization or generic TCP optimization.
133 type: str
134 choices:
135 - 'protocol'
136 - 'tcp'
137 secure_tunnel:
138 description:
139 - Enable/disable securing the WAN Opt tunnel using SSL. Secure and non-secure tunnels use the same TCP port (7810).
140 type: str
141 choices:
142 - 'enable'
143 - 'disable'
144 status:
145 description:
146 - Enable/disable WAN Optimization.
147 type: str
148 choices:
149 - 'enable'
150 - 'disable'
151 tunnel_sharing:
152 description:
153 - Tunnel sharing mode for aggressive/non-aggressive and/or interactive/non-interactive protocols.
154 type: str
155 choices:
156 - 'shared'
157 - 'express-shared'
158 - 'private'
159 comments:
160 description:
161 - Comment.
162 type: str
163 ftp:
164 description:
165 - Enable/disable FTP WAN Optimization and configure FTP WAN Optimization features.
166 type: dict
167 suboptions:
168 byte_caching:
169 description:
170 - Enable/disable byte-caching. Byte caching reduces the amount of traffic by caching file data sent across the WAN and in future
171 serving if from the cache.
172 type: str
173 choices:
174 - 'enable'
175 - 'disable'
176 log_traffic:
177 description:
178 - Enable/disable logging.
179 type: str
180 choices:
181 - 'enable'
182 - 'disable'
183 port:
184 description:
185 - Single port number or port number range for FTP. Only packets with a destination port number that matches this port number or
186 range are accepted by this profile.
187 type: int
188 prefer_chunking:
189 description:
190 - Select dynamic or fixed-size data chunking for WAN Optimization.
191 type: str
192 choices:
193 - 'dynamic'
194 - 'fix'
195 protocol_opt:
196 description:
197 - Select protocol specific optimization or generic TCP optimization.
198 type: str
199 choices:
200 - 'protocol'
201 - 'tcp'
202 secure_tunnel:
203 description:
204 - Enable/disable securing the WAN Opt tunnel using SSL. Secure and non-secure tunnels use the same TCP port (7810).
205 type: str
206 choices:
207 - 'enable'
208 - 'disable'
209 ssl:
210 description:
211 - Enable/disable SSL/TLS offloading (hardware acceleration) for traffic in this tunnel.
212 type: str
213 choices:
214 - 'enable'
215 - 'disable'
216 status:
217 description:
218 - Enable/disable WAN Optimization.
219 type: str
220 choices:
221 - 'enable'
222 - 'disable'
223 tunnel_sharing:
224 description:
225 - Tunnel sharing mode for aggressive/non-aggressive and/or interactive/non-interactive protocols.
226 type: str
227 choices:
228 - 'shared'
229 - 'express-shared'
230 - 'private'
231 http:
232 description:
233 - Enable/disable HTTP WAN Optimization and configure HTTP WAN Optimization features.
234 type: dict
235 suboptions:
236 byte_caching:
237 description:
238 - Enable/disable byte-caching. Byte caching reduces the amount of traffic by caching file data sent across the WAN and in future
239 serving if from the cache.
240 type: str
241 choices:
242 - 'enable'
243 - 'disable'
244 log_traffic:
245 description:
246 - Enable/disable logging.
247 type: str
248 choices:
249 - 'enable'
250 - 'disable'
251 port:
252 description:
253 - Single port number or port number range for HTTP. Only packets with a destination port number that matches this port number or
254 range are accepted by this profile.
255 type: int
256 prefer_chunking:
257 description:
258 - Select dynamic or fixed-size data chunking for WAN Optimization.
259 type: str
260 choices:
261 - 'dynamic'
262 - 'fix'
263 protocol_opt:
264 description:
265 - Select protocol specific optimization or generic TCP optimization.
266 type: str
267 choices:
268 - 'protocol'
269 - 'tcp'
270 secure_tunnel:
271 description:
272 - Enable/disable securing the WAN Opt tunnel using SSL. Secure and non-secure tunnels use the same TCP port (7810).
273 type: str
274 choices:
275 - 'enable'
276 - 'disable'
277 ssl:
278 description:
279 - Enable/disable SSL/TLS offloading (hardware acceleration) for traffic in this tunnel.
280 type: str
281 choices:
282 - 'enable'
283 - 'disable'
284 ssl_port:
285 description:
286 - Port on which to expect HTTPS traffic for SSL/TLS offloading.
287 type: int
288 status:
289 description:
290 - Enable/disable WAN Optimization.
291 type: str
292 choices:
293 - 'enable'
294 - 'disable'
295 tunnel_non_http:
296 description:
297 - Configure how to process non-HTTP traffic when a profile configured for HTTP traffic accepts a non-HTTP session. Can occur if an
298 application sends non-HTTP traffic using an HTTP destination port.
299 type: str
300 choices:
301 - 'enable'
302 - 'disable'
303 tunnel_sharing:
304 description:
305 - Tunnel sharing mode for aggressive/non-aggressive and/or interactive/non-interactive protocols.
306 type: str
307 choices:
308 - 'shared'
309 - 'express-shared'
310 - 'private'
311 unknown_http_version:
312 description:
313 - How to handle HTTP sessions that do not comply with HTTP 0.9, 1.0, or 1.1.
314 type: str
315 choices:
316 - 'reject'
317 - 'tunnel'
318 - 'best-effort'
319 mapi:
320 description:
321 - Enable/disable MAPI email WAN Optimization and configure MAPI WAN Optimization features.
322 type: dict
323 suboptions:
324 byte_caching:
325 description:
326 - Enable/disable byte-caching. Byte caching reduces the amount of traffic by caching file data sent across the WAN and in future
327 serving if from the cache.
328 type: str
329 choices:
330 - 'enable'
331 - 'disable'
332 log_traffic:
333 description:
334 - Enable/disable logging.
335 type: str
336 choices:
337 - 'enable'
338 - 'disable'
339 port:
340 description:
341 - Single port number or port number range for MAPI. Only packets with a destination port number that matches this port number or
342 range are accepted by this profile.
343 type: int
344 secure_tunnel:
345 description:
346 - Enable/disable securing the WAN Opt tunnel using SSL. Secure and non-secure tunnels use the same TCP port (7810).
347 type: str
348 choices:
349 - 'enable'
350 - 'disable'
351 status:
352 description:
353 - Enable/disable WAN Optimization.
354 type: str
355 choices:
356 - 'enable'
357 - 'disable'
358 tunnel_sharing:
359 description:
360 - Tunnel sharing mode for aggressive/non-aggressive and/or interactive/non-interactive protocols.
361 type: str
362 choices:
363 - 'shared'
364 - 'express-shared'
365 - 'private'
366 name:
367 description:
368 - Profile name.
369 required: true
370 type: str
371 tcp:
372 description:
373 - Enable/disable TCP WAN Optimization and configure TCP WAN Optimization features.
374 type: dict
375 suboptions:
376 byte_caching:
377 description:
378 - Enable/disable byte-caching. Byte caching reduces the amount of traffic by caching file data sent across the WAN and in future
379 serving if from the cache.
380 type: str
381 choices:
382 - 'enable'
383 - 'disable'
384 byte_caching_opt:
385 description:
386 - Select whether TCP byte-caching uses system memory only or both memory and disk space.
387 type: str
388 choices:
389 - 'mem-only'
390 - 'mem-disk'
391 log_traffic:
392 description:
393 - Enable/disable logging.
394 type: str
395 choices:
396 - 'enable'
397 - 'disable'
398 port:
399 description:
400 - Port numbers or port number ranges for TCP. Only packets with a destination port number that matches this port number or range
401 are accepted by this profile.
402 type: str
403 secure_tunnel:
404 description:
405 - Enable/disable securing the WAN Opt tunnel using SSL. Secure and non-secure tunnels use the same TCP port (7810).
406 type: str
407 choices:
408 - 'enable'
409 - 'disable'
410 ssl:
411 description:
412 - Enable/disable SSL/TLS offloading (hardware acceleration) for traffic in this tunnel.
413 type: str
414 choices:
415 - 'enable'
416 - 'disable'
417 ssl_port:
418 description:
419 - Port numbers or port number ranges on which to expect HTTPS traffic for SSL/TLS offloading.
420 type: str
421 status:
422 description:
423 - Enable/disable WAN Optimization.
424 type: str
425 choices:
426 - 'enable'
427 - 'disable'
428 tunnel_sharing:
429 description:
430 - Tunnel sharing mode for aggressive/non-aggressive and/or interactive/non-interactive protocols.
431 type: str
432 choices:
433 - 'shared'
434 - 'express-shared'
435 - 'private'
436 transparent:
437 description:
438 - Enable/disable transparent mode.
439 type: str
440 choices:
441 - 'enable'
442 - 'disable'
443 """
444
445 EXAMPLES = """
446 - name: Configure WAN optimization profiles.
447 fortinet.fortios.fortios_wanopt_profile:
448 vdom: "{{ vdom }}"
449 state: "present"
450 access_token: "<your_own_value>"
451 wanopt_profile:
452 auth_group: "<your_own_value> (source wanopt.auth-group.name)"
453 cifs:
454 byte_caching: "enable"
455 log_traffic: "enable"
456 port: "32767"
457 prefer_chunking: "dynamic"
458 protocol_opt: "protocol"
459 secure_tunnel: "enable"
460 status: "enable"
461 tunnel_sharing: "shared"
462 comments: "<your_own_value>"
463 ftp:
464 byte_caching: "enable"
465 log_traffic: "enable"
466 port: "32767"
467 prefer_chunking: "dynamic"
468 protocol_opt: "protocol"
469 secure_tunnel: "enable"
470 ssl: "enable"
471 status: "enable"
472 tunnel_sharing: "shared"
473 http:
474 byte_caching: "enable"
475 log_traffic: "enable"
476 port: "32767"
477 prefer_chunking: "dynamic"
478 protocol_opt: "protocol"
479 secure_tunnel: "enable"
480 ssl: "enable"
481 ssl_port: "32767"
482 status: "enable"
483 tunnel_non_http: "enable"
484 tunnel_sharing: "shared"
485 unknown_http_version: "reject"
486 mapi:
487 byte_caching: "enable"
488 log_traffic: "enable"
489 port: "32767"
490 secure_tunnel: "enable"
491 status: "enable"
492 tunnel_sharing: "shared"
493 name: "default_name_44"
494 tcp:
495 byte_caching: "enable"
496 byte_caching_opt: "mem-only"
497 log_traffic: "enable"
498 port: "<your_own_value>"
499 secure_tunnel: "enable"
500 ssl: "enable"
501 ssl_port: "<your_own_value>"
502 status: "enable"
503 tunnel_sharing: "shared"
504 transparent: "enable"
505 """
506
507 RETURN = """
508 build:
509 description: Build number of the fortigate image
510 returned: always
511 type: str
512 sample: '1547'
513 http_method:
514 description: Last method used to provision the content into FortiGate
515 returned: always
516 type: str
517 sample: 'PUT'
518 http_status:
519 description: Last result given by FortiGate on last operation applied
520 returned: always
521 type: str
522 sample: "200"
523 mkey:
524 description: Master key (id) used in the last call to FortiGate
525 returned: success
526 type: str
527 sample: "id"
528 name:
529 description: Name of the table used to fulfill the request
530 returned: always
531 type: str
532 sample: "urlfilter"
533 path:
534 description: Path of the table used to fulfill the request
535 returned: always
536 type: str
537 sample: "webfilter"
538 revision:
539 description: Internal revision number
540 returned: always
541 type: str
542 sample: "17.0.2.10658"
543 serial:
544 description: Serial number of the unit
545 returned: always
546 type: str
547 sample: "FGVMEVYYQT3AB5352"
548 status:
549 description: Indication of the operation's result
550 returned: always
551 type: str
552 sample: "success"
553 vdom:
554 description: Virtual domain used
555 returned: always
556 type: str
557 sample: "root"
558 version:
559 description: Version of the FortiGate
560 returned: always
561 type: str
562 sample: "v5.6.3"
563 """
564 from ansible.module_utils.basic import AnsibleModule
565 from ansible.module_utils.connection import Connection
566 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
567 FortiOSHandler,
568 )
569 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
570 check_legacy_fortiosapi,
571 )
572 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
573 schema_to_module_spec,
574 )
575 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
576 check_schema_versioning,
577 )
578 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
579 FAIL_SOCKET_MSG,
580 )
581 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
582 remove_invalid_fields,
583 )
584 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
585 is_same_comparison,
586 )
587 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
588 serialize,
589 )
590 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
591 find_current_values,
592 )
593 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
594 unify_data_format,
595 )
596
597
598 def filter_wanopt_profile_data(json):
599 option_list = [
600 "auth_group",
601 "cifs",
602 "comments",
603 "ftp",
604 "http",
605 "mapi",
606 "name",
607 "tcp",
608 "transparent",
609 ]
610
611 json = remove_invalid_fields(json)
612 dictionary = {}
613
614 for attribute in option_list:
615 if attribute in json and json[attribute] is not None:
616 dictionary[attribute] = json[attribute]
617
618 return dictionary
619
620
621 def underscore_to_hyphen(data):
622 new_data = None
623 if isinstance(data, list):
624 new_data = []
625 for i, elem in enumerate(data):
626 new_data.append(underscore_to_hyphen(elem))
627 elif isinstance(data, dict):
628 new_data = {}
629 for k, v in data.items():
630 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
631 else:
632 return data
633 return new_data
634
635
636 def wanopt_profile(data, fos, check_mode=False):
637
638 state = None
639 vdom = data["vdom"]
640 parameters = None
641 state = data.get("state", None)
642 wanopt_profile_data = data["wanopt_profile"]
643
644 filtered_data = filter_wanopt_profile_data(wanopt_profile_data)
645 converted_data = underscore_to_hyphen(filtered_data)
646
647 # check_mode starts from here
648 if check_mode:
649 diff = {
650 "before": "",
651 "after": filtered_data,
652 }
653 mkeyname = fos.get_mkeyname(None, None)
654 mkey = fos.get_mkey("wanopt", "profile", filtered_data, vdom=vdom)
655 current_data = fos.get(
656 "wanopt", "profile", vdom=vdom, mkey=mkey, parameters=parameters
657 )
658 is_existed = (
659 current_data
660 and current_data.get("http_status") == 200
661 and (
662 mkeyname
663 and isinstance(current_data.get("results"), list)
664 and len(current_data["results"]) > 0
665 or not mkeyname
666 and current_data["results"] # global object response
667 )
668 )
669
670 # 2. if it exists and the state is 'present' then compare current settings with desired
671 if state == "present" or state is True or state is None:
672 # for non global modules, mkeyname must exist and it's a new module when mkey is None
673 if mkeyname is not None and mkey is None:
674 return False, True, filtered_data, diff
675
676 # if mkey exists then compare each other
677 # record exits and they're matched or not
678 copied_filtered_data = filtered_data.copy()
679 copied_filtered_data.pop(mkeyname, None)
680 unified_filtered_data = unify_data_format(copied_filtered_data)
681
682 current_data_results = current_data.get("results", {})
683 current_config = (
684 current_data_results[0]
685 if mkeyname
686 and isinstance(current_data_results, list)
687 and len(current_data_results) > 0
688 else current_data_results
689 )
690 if is_existed:
691 unified_current_values = find_current_values(
692 unified_filtered_data,
693 unify_data_format(current_config),
694 )
695
696 is_same = is_same_comparison(
697 serialize(unified_current_values), serialize(unified_filtered_data)
698 )
699
700 return (
701 False,
702 not is_same,
703 filtered_data,
704 {"before": unified_current_values, "after": unified_filtered_data},
705 )
706
707 # record does not exist
708 return False, True, filtered_data, diff
709
710 if state == "absent":
711 if mkey is None:
712 return (
713 False,
714 False,
715 filtered_data,
716 {"before": current_data["results"][0], "after": ""},
717 )
718
719 if is_existed:
720 return (
721 False,
722 True,
723 filtered_data,
724 {"before": current_data["results"][0], "after": ""},
725 )
726 return False, False, filtered_data, {}
727
728 return True, False, {"reason: ": "Must provide state parameter"}, {}
729 # pass post processed data to member operations
730 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
731 data_copy = data.copy()
732 data_copy["wanopt_profile"] = filtered_data
733 fos.do_member_operation(
734 "wanopt",
735 "profile",
736 data_copy,
737 )
738
739 if state == "present" or state is True:
740 return fos.set(
741 "wanopt", "profile", data=converted_data, vdom=vdom, parameters=parameters
742 )
743
744 elif state == "absent":
745 return fos.delete(
746 "wanopt",
747 "profile",
748 mkey=converted_data["name"],
749 vdom=vdom,
750 parameters=parameters,
751 )
752 else:
753 fos._module.fail_json(msg="state must be present or absent!")
754
755
756 def is_successful_status(resp):
757 return (
758 "status" in resp
759 and resp["status"] == "success"
760 or "http_status" in resp
761 and resp["http_status"] == 200
762 or "http_method" in resp
763 and resp["http_method"] == "DELETE"
764 and resp["http_status"] == 404
765 )
766
767
768 def fortios_wanopt(data, fos, check_mode):
769
770 if data["wanopt_profile"]:
771 resp = wanopt_profile(data, fos, check_mode)
772 else:
773 fos._module.fail_json(msg="missing task body: %s" % ("wanopt_profile"))
774 if isinstance(resp, tuple) and len(resp) == 4:
775 return resp
776 return (
777 not is_successful_status(resp),
778 is_successful_status(resp)
779 and (resp["revision_changed"] if "revision_changed" in resp else True),
780 resp,
781 {},
782 )
783
784
785 versioned_schema = {
786 "type": "list",
787 "elements": "dict",
788 "children": {
789 "name": {"v_range": [["v6.0.0", ""]], "type": "string", "required": True},
790 "transparent": {
791 "v_range": [["v6.0.0", ""]],
792 "type": "string",
793 "options": [{"value": "enable"}, {"value": "disable"}],
794 },
795 "comments": {"v_range": [["v6.0.0", ""]], "type": "string"},
796 "auth_group": {"v_range": [["v6.0.0", ""]], "type": "string"},
797 "http": {
798 "v_range": [["v6.0.0", ""]],
799 "type": "dict",
800 "children": {
801 "status": {
802 "v_range": [["v6.0.0", ""]],
803 "type": "string",
804 "options": [{"value": "enable"}, {"value": "disable"}],
805 },
806 "secure_tunnel": {
807 "v_range": [["v6.0.0", ""]],
808 "type": "string",
809 "options": [{"value": "enable"}, {"value": "disable"}],
810 },
811 "byte_caching": {
812 "v_range": [["v6.0.0", ""]],
813 "type": "string",
814 "options": [{"value": "enable"}, {"value": "disable"}],
815 },
816 "ssl": {
817 "v_range": [["v6.0.0", ""]],
818 "type": "string",
819 "options": [{"value": "enable"}, {"value": "disable"}],
820 },
821 "prefer_chunking": {
822 "v_range": [["v6.0.0", ""]],
823 "type": "string",
824 "options": [{"value": "dynamic"}, {"value": "fix"}],
825 },
826 "protocol_opt": {
827 "v_range": [["v6.4.0", ""]],
828 "type": "string",
829 "options": [{"value": "protocol"}, {"value": "tcp"}],
830 },
831 "tunnel_sharing": {
832 "v_range": [["v6.0.0", ""]],
833 "type": "string",
834 "options": [
835 {"value": "shared"},
836 {"value": "express-shared"},
837 {"value": "private"},
838 ],
839 },
840 "log_traffic": {
841 "v_range": [["v6.0.0", "v7.2.2"]],
842 "type": "string",
843 "options": [{"value": "enable"}, {"value": "disable"}],
844 },
845 "port": {"v_range": [["v6.0.0", "v6.2.7"]], "type": "integer"},
846 "ssl_port": {"v_range": [["v6.0.0", "v6.2.7"]], "type": "integer"},
847 "unknown_http_version": {
848 "v_range": [["v6.0.0", "v6.2.7"]],
849 "type": "string",
850 "options": [
851 {"value": "reject"},
852 {"value": "tunnel"},
853 {"value": "best-effort"},
854 ],
855 },
856 "tunnel_non_http": {
857 "v_range": [["v6.0.0", "v6.2.7"]],
858 "type": "string",
859 "options": [{"value": "enable"}, {"value": "disable"}],
860 },
861 },
862 },
863 "cifs": {
864 "v_range": [["v6.0.0", ""]],
865 "type": "dict",
866 "children": {
867 "status": {
868 "v_range": [["v6.0.0", ""]],
869 "type": "string",
870 "options": [{"value": "enable"}, {"value": "disable"}],
871 },
872 "secure_tunnel": {
873 "v_range": [["v6.0.0", ""]],
874 "type": "string",
875 "options": [{"value": "enable"}, {"value": "disable"}],
876 },
877 "byte_caching": {
878 "v_range": [["v6.0.0", ""]],
879 "type": "string",
880 "options": [{"value": "enable"}, {"value": "disable"}],
881 },
882 "prefer_chunking": {
883 "v_range": [["v6.0.0", ""]],
884 "type": "string",
885 "options": [{"value": "dynamic"}, {"value": "fix"}],
886 },
887 "protocol_opt": {
888 "v_range": [["v6.4.0", ""]],
889 "type": "string",
890 "options": [{"value": "protocol"}, {"value": "tcp"}],
891 },
892 "tunnel_sharing": {
893 "v_range": [["v6.0.0", ""]],
894 "type": "string",
895 "options": [
896 {"value": "shared"},
897 {"value": "express-shared"},
898 {"value": "private"},
899 ],
900 },
901 "log_traffic": {
902 "v_range": [["v6.0.0", "v7.2.2"]],
903 "type": "string",
904 "options": [{"value": "enable"}, {"value": "disable"}],
905 },
906 "port": {"v_range": [["v6.0.0", "v6.2.7"]], "type": "integer"},
907 },
908 },
909 "mapi": {
910 "v_range": [["v6.0.0", ""]],
911 "type": "dict",
912 "children": {
913 "status": {
914 "v_range": [["v6.0.0", ""]],
915 "type": "string",
916 "options": [{"value": "enable"}, {"value": "disable"}],
917 },
918 "secure_tunnel": {
919 "v_range": [["v6.0.0", ""]],
920 "type": "string",
921 "options": [{"value": "enable"}, {"value": "disable"}],
922 },
923 "byte_caching": {
924 "v_range": [["v6.0.0", ""]],
925 "type": "string",
926 "options": [{"value": "enable"}, {"value": "disable"}],
927 },
928 "tunnel_sharing": {
929 "v_range": [["v6.0.0", ""]],
930 "type": "string",
931 "options": [
932 {"value": "shared"},
933 {"value": "express-shared"},
934 {"value": "private"},
935 ],
936 },
937 "log_traffic": {
938 "v_range": [["v6.0.0", "v7.2.2"]],
939 "type": "string",
940 "options": [{"value": "enable"}, {"value": "disable"}],
941 },
942 "port": {"v_range": [["v6.0.0", "v6.2.7"]], "type": "integer"},
943 },
944 },
945 "ftp": {
946 "v_range": [["v6.0.0", ""]],
947 "type": "dict",
948 "children": {
949 "status": {
950 "v_range": [["v6.0.0", ""]],
951 "type": "string",
952 "options": [{"value": "enable"}, {"value": "disable"}],
953 },
954 "secure_tunnel": {
955 "v_range": [["v6.0.0", ""]],
956 "type": "string",
957 "options": [{"value": "enable"}, {"value": "disable"}],
958 },
959 "byte_caching": {
960 "v_range": [["v6.0.0", ""]],
961 "type": "string",
962 "options": [{"value": "enable"}, {"value": "disable"}],
963 },
964 "prefer_chunking": {
965 "v_range": [["v6.0.0", ""]],
966 "type": "string",
967 "options": [{"value": "dynamic"}, {"value": "fix"}],
968 },
969 "protocol_opt": {
970 "v_range": [["v6.4.0", ""]],
971 "type": "string",
972 "options": [{"value": "protocol"}, {"value": "tcp"}],
973 },
974 "tunnel_sharing": {
975 "v_range": [["v6.0.0", ""]],
976 "type": "string",
977 "options": [
978 {"value": "shared"},
979 {"value": "express-shared"},
980 {"value": "private"},
981 ],
982 },
983 "ssl": {
984 "v_range": [["v6.4.0", "v7.2.2"]],
985 "type": "string",
986 "options": [{"value": "enable"}, {"value": "disable"}],
987 },
988 "log_traffic": {
989 "v_range": [["v6.0.0", "v7.2.2"]],
990 "type": "string",
991 "options": [{"value": "enable"}, {"value": "disable"}],
992 },
993 "port": {"v_range": [["v6.0.0", "v6.2.7"]], "type": "integer"},
994 },
995 },
996 "tcp": {
997 "v_range": [["v6.0.0", ""]],
998 "type": "dict",
999 "children": {
1000 "status": {
1001 "v_range": [["v6.0.0", ""]],
1002 "type": "string",
1003 "options": [{"value": "enable"}, {"value": "disable"}],
1004 },
1005 "secure_tunnel": {
1006 "v_range": [["v6.0.0", ""]],
1007 "type": "string",
1008 "options": [{"value": "enable"}, {"value": "disable"}],
1009 },
1010 "byte_caching": {
1011 "v_range": [["v6.0.0", ""]],
1012 "type": "string",
1013 "options": [{"value": "enable"}, {"value": "disable"}],
1014 },
1015 "byte_caching_opt": {
1016 "v_range": [["v6.0.0", ""]],
1017 "type": "string",
1018 "options": [{"value": "mem-only"}, {"value": "mem-disk"}],
1019 },
1020 "tunnel_sharing": {
1021 "v_range": [["v6.0.0", ""]],
1022 "type": "string",
1023 "options": [
1024 {"value": "shared"},
1025 {"value": "express-shared"},
1026 {"value": "private"},
1027 ],
1028 },
1029 "port": {"v_range": [["v6.0.0", ""]], "type": "string"},
1030 "ssl": {
1031 "v_range": [["v6.0.0", ""]],
1032 "type": "string",
1033 "options": [{"value": "enable"}, {"value": "disable"}],
1034 },
1035 "ssl_port": {"v_range": [["v6.0.0", ""]], "type": "string"},
1036 "log_traffic": {
1037 "v_range": [["v6.0.0", "v7.2.2"]],
1038 "type": "string",
1039 "options": [{"value": "enable"}, {"value": "disable"}],
1040 },
1041 },
1042 },
1043 },
1044 "v_range": [["v6.0.0", ""]],
1045 }
1046
1047
1048 def main():
1049 module_spec = schema_to_module_spec(versioned_schema)
1050 mkeyname = "name"
1051 fields = {
1052 "access_token": {"required": False, "type": "str", "no_log": True},
1053 "enable_log": {"required": False, "type": "bool", "default": False},
1054 "vdom": {"required": False, "type": "str", "default": "root"},
1055 "member_path": {"required": False, "type": "str"},
1056 "member_state": {
1057 "type": "str",
1058 "required": False,
1059 "choices": ["present", "absent"],
1060 },
1061 "state": {"required": True, "type": "str", "choices": ["present", "absent"]},
1062 "wanopt_profile": {
1063 "required": False,
1064 "type": "dict",
1065 "default": None,
1066 "options": {},
1067 },
1068 }
1069 for attribute_name in module_spec["options"]:
1070 fields["wanopt_profile"]["options"][attribute_name] = module_spec["options"][
1071 attribute_name
1072 ]
1073 if mkeyname and mkeyname == attribute_name:
1074 fields["wanopt_profile"]["options"][attribute_name]["required"] = True
1075
1076 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
1077 check_legacy_fortiosapi(module)
1078
1079 is_error = False
1080 has_changed = False
1081 result = None
1082 diff = None
1083
1084 versions_check_result = None
1085 if module._socket_path:
1086 connection = Connection(module._socket_path)
1087 if "access_token" in module.params:
1088 connection.set_custom_option("access_token", module.params["access_token"])
1089
1090 if "enable_log" in module.params:
1091 connection.set_custom_option("enable_log", module.params["enable_log"])
1092 else:
1093 connection.set_custom_option("enable_log", False)
1094 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
1095 versions_check_result = check_schema_versioning(
1096 fos, versioned_schema, "wanopt_profile"
1097 )
1098
1099 is_error, has_changed, result, diff = fortios_wanopt(
1100 module.params, fos, module.check_mode
1101 )
1102
1103 else:
1104 module.fail_json(**FAIL_SOCKET_MSG)
1105
1106 if versions_check_result and versions_check_result["matched"] is False:
1107 module.warn(
1108 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
1109 )
1110
1111 if not is_error:
1112 if versions_check_result and versions_check_result["matched"] is False:
1113 module.exit_json(
1114 changed=has_changed,
1115 version_check_warning=versions_check_result,
1116 meta=result,
1117 diff=diff,
1118 )
1119 else:
1120 module.exit_json(changed=has_changed, meta=result, diff=diff)
1121 else:
1122 if versions_check_result and versions_check_result["matched"] is False:
1123 module.fail_json(
1124 msg="Error in repo",
1125 version_check_warning=versions_check_result,
1126 meta=result,
1127 )
1128 else:
1129 module.fail_json(msg="Error in repo", meta=result)
1130
1131
1132 if __name__ == "__main__":
1133 main()