Debian Codegraph @

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