Debian Codegraph @

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