Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_antivirus_quarantine.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_antivirus_quarantine
23 short_description: Configure quarantine options 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 antivirus feature and quarantine 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 antivirus_quarantine:
80 description:
81 - Configure quarantine options.
82 default: null
83 type: dict
84 suboptions:
85 agelimit:
86 description:
87 - Age limit for quarantined files (0 - 479 hours, 0 means forever).
88 type: int
89 destination:
90 description:
91 - Choose whether to quarantine files to the FortiGate disk or to FortiAnalyzer or to delete them instead of quarantining them.
92 type: str
93 choices:
94 - 'NULL'
95 - 'disk'
96 - 'FortiAnalyzer'
97 drop_blocked:
98 description:
99 - Do not quarantine dropped files found in sessions using the selected protocols. Dropped files are deleted instead of being quarantined.
100 type: list
101 elements: str
102 choices:
103 - 'imap'
104 - 'smtp'
105 - 'pop3'
106 - 'http'
107 - 'ftp'
108 - 'nntp'
109 - 'imaps'
110 - 'smtps'
111 - 'pop3s'
112 - 'https'
113 - 'ftps'
114 - 'mapi'
115 - 'cifs'
116 - 'ssh'
117 - 'mm1'
118 - 'mm3'
119 - 'mm4'
120 - 'mm7'
121 drop_heuristic:
122 description:
123 - Do not quarantine files detected by heuristics found in sessions using the selected protocols. Dropped files are deleted instead of
124 being quarantined.
125 type: list
126 elements: str
127 choices:
128 - 'imap'
129 - 'smtp'
130 - 'pop3'
131 - 'http'
132 - 'ftp'
133 - 'nntp'
134 - 'imaps'
135 - 'smtps'
136 - 'pop3s'
137 - 'https'
138 - 'ftps'
139 - 'mapi'
140 - 'cifs'
141 - 'ssh'
142 - 'mm1'
143 - 'mm3'
144 - 'mm4'
145 - 'mm7'
146 drop_infected:
147 description:
148 - Do not quarantine infected files found in sessions using the selected protocols. Dropped files are deleted instead of being quarantined.
149 type: list
150 elements: str
151 choices:
152 - 'imap'
153 - 'smtp'
154 - 'pop3'
155 - 'http'
156 - 'ftp'
157 - 'nntp'
158 - 'imaps'
159 - 'smtps'
160 - 'pop3s'
161 - 'https'
162 - 'ftps'
163 - 'mapi'
164 - 'cifs'
165 - 'ssh'
166 - 'mm1'
167 - 'mm3'
168 - 'mm4'
169 - 'mm7'
170 drop_intercepted:
171 description:
172 - drop intercepted from a protocol
173 type: list
174 elements: str
175 choices:
176 - 'imap'
177 - 'smtp'
178 - 'pop3'
179 - 'http'
180 - 'ftp'
181 - 'imaps'
182 - 'smtps'
183 - 'pop3s'
184 - 'https'
185 - 'ftps'
186 - 'mapi'
187 - 'mm1'
188 - 'mm3'
189 - 'mm4'
190 - 'mm7'
191 drop_machine_learning:
192 description:
193 - Do not quarantine files detected by machine learning found in sessions using the selected protocols. Dropped files are deleted instead
194 of being quarantined.
195 type: list
196 elements: str
197 choices:
198 - 'imap'
199 - 'smtp'
200 - 'pop3'
201 - 'http'
202 - 'ftp'
203 - 'nntp'
204 - 'imaps'
205 - 'smtps'
206 - 'pop3s'
207 - 'https'
208 - 'ftps'
209 - 'mapi'
210 - 'cifs'
211 - 'ssh'
212 lowspace:
213 description:
214 - Select the method for handling additional files when running low on disk space.
215 type: str
216 choices:
217 - 'drop-new'
218 - 'ovrw-old'
219 maxfilesize:
220 description:
221 - Maximum file size to quarantine (0 - 500 Mbytes, 0 means unlimited).
222 type: int
223 quarantine_quota:
224 description:
225 - The amount of disk space to reserve for quarantining files (0 - 4294967295 Mbytes, 0 means unlimited and depends on disk space).
226 type: int
227 store_blocked:
228 description:
229 - Quarantine blocked files found in sessions using the selected protocols.
230 type: list
231 elements: str
232 choices:
233 - 'imap'
234 - 'smtp'
235 - 'pop3'
236 - 'http'
237 - 'ftp'
238 - 'nntp'
239 - 'imaps'
240 - 'smtps'
241 - 'pop3s'
242 - 'https'
243 - 'ftps'
244 - 'mapi'
245 - 'cifs'
246 - 'ssh'
247 - 'mm1'
248 - 'mm3'
249 - 'mm4'
250 - 'mm7'
251 store_heuristic:
252 description:
253 - Quarantine files detected by heuristics found in sessions using the selected protocols.
254 type: list
255 elements: str
256 choices:
257 - 'imap'
258 - 'smtp'
259 - 'pop3'
260 - 'http'
261 - 'ftp'
262 - 'nntp'
263 - 'imaps'
264 - 'smtps'
265 - 'pop3s'
266 - 'https'
267 - 'ftps'
268 - 'mapi'
269 - 'cifs'
270 - 'ssh'
271 - 'mm1'
272 - 'mm3'
273 - 'mm4'
274 - 'mm7'
275 store_infected:
276 description:
277 - Quarantine infected files found in sessions using the selected protocols.
278 type: list
279 elements: str
280 choices:
281 - 'imap'
282 - 'smtp'
283 - 'pop3'
284 - 'http'
285 - 'ftp'
286 - 'nntp'
287 - 'imaps'
288 - 'smtps'
289 - 'pop3s'
290 - 'https'
291 - 'ftps'
292 - 'mapi'
293 - 'cifs'
294 - 'ssh'
295 - 'mm1'
296 - 'mm3'
297 - 'mm4'
298 - 'mm7'
299 store_intercepted:
300 description:
301 - quarantine intercepted from a protocol
302 type: list
303 elements: str
304 choices:
305 - 'imap'
306 - 'smtp'
307 - 'pop3'
308 - 'http'
309 - 'ftp'
310 - 'imaps'
311 - 'smtps'
312 - 'pop3s'
313 - 'https'
314 - 'ftps'
315 - 'mapi'
316 - 'mm1'
317 - 'mm3'
318 - 'mm4'
319 - 'mm7'
320 store_machine_learning:
321 description:
322 - Quarantine files detected by machine learning found in sessions using the selected protocols.
323 type: list
324 elements: str
325 choices:
326 - 'imap'
327 - 'smtp'
328 - 'pop3'
329 - 'http'
330 - 'ftp'
331 - 'nntp'
332 - 'imaps'
333 - 'smtps'
334 - 'pop3s'
335 - 'https'
336 - 'ftps'
337 - 'mapi'
338 - 'cifs'
339 - 'ssh'
340 """
341
342 EXAMPLES = """
343 - name: Configure quarantine options.
344 fortinet.fortios.fortios_antivirus_quarantine:
345 vdom: "{{ vdom }}"
346 antivirus_quarantine:
347 agelimit: "0"
348 destination: "NULL"
349 drop_blocked: "imap"
350 drop_heuristic: "imap"
351 drop_infected: "imap"
352 drop_intercepted: "imap"
353 drop_machine_learning: "imap"
354 lowspace: "drop-new"
355 maxfilesize: "0"
356 quarantine_quota: "0"
357 store_blocked: "imap"
358 store_heuristic: "imap"
359 store_infected: "imap"
360 store_intercepted: "imap"
361 store_machine_learning: "imap"
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_antivirus_quarantine_data(json):
456 option_list = [
457 "agelimit",
458 "destination",
459 "drop_blocked",
460 "drop_heuristic",
461 "drop_infected",
462 "drop_intercepted",
463 "drop_machine_learning",
464 "lowspace",
465 "maxfilesize",
466 "quarantine_quota",
467 "store_blocked",
468 "store_heuristic",
469 "store_infected",
470 "store_intercepted",
471 "store_machine_learning",
472 ]
473
474 json = remove_invalid_fields(json)
475 dictionary = {}
476
477 for attribute in option_list:
478 if attribute in json and json[attribute] is not None:
479 dictionary[attribute] = json[attribute]
480
481 return dictionary
482
483
484 def flatten_single_path(data, path, index):
485 if (
486 not data
487 or index == len(path)
488 or path[index] not in data
489 or (not data[path[index]] and not isinstance(data[path[index]], list))
490 ):
491 return
492
493 if index == len(path) - 1:
494 data[path[index]] = " ".join(str(elem) for elem in data[path[index]])
495 if len(data[path[index]]) == 0:
496 data[path[index]] = None
497 elif isinstance(data[path[index]], list):
498 for value in data[path[index]]:
499 flatten_single_path(value, path, index + 1)
500 else:
501 flatten_single_path(data[path[index]], path, index + 1)
502
503
504 def flatten_multilists_attributes(data):
505 multilist_attrs = [
506 ["drop_infected"],
507 ["store_infected"],
508 ["drop_machine_learning"],
509 ["store_machine_learning"],
510 ["drop_blocked"],
511 ["store_blocked"],
512 ["drop_heuristic"],
513 ["store_heuristic"],
514 ["drop_intercepted"],
515 ["store_intercepted"],
516 ]
517
518 for attr in multilist_attrs:
519 flatten_single_path(data, attr, 0)
520
521 return data
522
523
524 def underscore_to_hyphen(data):
525 new_data = None
526 if isinstance(data, list):
527 new_data = []
528 for i, elem in enumerate(data):
529 new_data.append(underscore_to_hyphen(elem))
530 elif isinstance(data, dict):
531 new_data = {}
532 for k, v in data.items():
533 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
534 else:
535 return data
536 return new_data
537
538
539 def antivirus_quarantine(data, fos, check_mode=False):
540
541 state = None
542 vdom = data["vdom"]
543 parameters = None
544 state = data.get("state", None)
545 antivirus_quarantine_data = data["antivirus_quarantine"]
546
547 filtered_data = filter_antivirus_quarantine_data(antivirus_quarantine_data)
548 filtered_data = flatten_multilists_attributes(filtered_data)
549 converted_data = underscore_to_hyphen(filtered_data)
550
551 # check_mode starts from here
552 if check_mode:
553 diff = {
554 "before": "",
555 "after": filtered_data,
556 }
557 mkeyname = fos.get_mkeyname(None, None)
558 mkey = fos.get_mkey("antivirus", "quarantine", filtered_data, vdom=vdom)
559 current_data = fos.get(
560 "antivirus", "quarantine", vdom=vdom, mkey=mkey, parameters=parameters
561 )
562 is_existed = (
563 current_data
564 and current_data.get("http_status") == 200
565 and (
566 mkeyname
567 and isinstance(current_data.get("results"), list)
568 and len(current_data["results"]) > 0
569 or not mkeyname
570 and current_data["results"] # global object response
571 )
572 )
573
574 # 2. if it exists and the state is 'present' then compare current settings with desired
575 if state == "present" or state is True or state is None:
576 # for non global modules, mkeyname must exist and it's a new module when mkey is None
577 if mkeyname is not None and mkey is None:
578 return False, True, filtered_data, diff
579
580 # if mkey exists then compare each other
581 # record exits and they're matched or not
582 copied_filtered_data = filtered_data.copy()
583 copied_filtered_data.pop(mkeyname, None)
584 unified_filtered_data = unify_data_format(copied_filtered_data)
585
586 current_data_results = current_data.get("results", {})
587 current_config = (
588 current_data_results[0]
589 if mkeyname
590 and isinstance(current_data_results, list)
591 and len(current_data_results) > 0
592 else current_data_results
593 )
594 if is_existed:
595 unified_current_values = find_current_values(
596 unified_filtered_data,
597 unify_data_format(current_config),
598 )
599
600 is_same = is_same_comparison(
601 serialize(unified_current_values), serialize(unified_filtered_data)
602 )
603
604 return (
605 False,
606 not is_same,
607 filtered_data,
608 {"before": unified_current_values, "after": unified_filtered_data},
609 )
610
611 # record does not exist
612 return False, True, filtered_data, diff
613
614 if state == "absent":
615 if mkey is None:
616 return (
617 False,
618 False,
619 filtered_data,
620 {"before": current_data["results"][0], "after": ""},
621 )
622
623 if is_existed:
624 return (
625 False,
626 True,
627 filtered_data,
628 {"before": current_data["results"][0], "after": ""},
629 )
630 return False, False, filtered_data, {}
631
632 return True, False, {"reason: ": "Must provide state parameter"}, {}
633 # pass post processed data to member operations
634 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
635 data_copy = data.copy()
636 data_copy["antivirus_quarantine"] = filtered_data
637 fos.do_member_operation(
638 "antivirus",
639 "quarantine",
640 data_copy,
641 )
642
643 return fos.set(
644 "antivirus", "quarantine", data=converted_data, vdom=vdom, parameters=parameters
645 )
646
647
648 def is_successful_status(resp):
649 return (
650 "status" in resp
651 and resp["status"] == "success"
652 or "http_status" in resp
653 and resp["http_status"] == 200
654 or "http_method" in resp
655 and resp["http_method"] == "DELETE"
656 and resp["http_status"] == 404
657 )
658
659
660 def fortios_antivirus(data, fos, check_mode):
661
662 if data["antivirus_quarantine"]:
663 resp = antivirus_quarantine(data, fos, check_mode)
664 else:
665 fos._module.fail_json(msg="missing task body: %s" % ("antivirus_quarantine"))
666 if isinstance(resp, tuple) and len(resp) == 4:
667 return resp
668 return (
669 not is_successful_status(resp),
670 is_successful_status(resp)
671 and (resp["revision_changed"] if "revision_changed" in resp else True),
672 resp,
673 {},
674 )
675
676
677 versioned_schema = {
678 "v_range": [["v6.0.0", ""]],
679 "type": "dict",
680 "children": {
681 "agelimit": {"v_range": [["v6.0.0", ""]], "type": "integer"},
682 "maxfilesize": {"v_range": [["v6.0.0", ""]], "type": "integer"},
683 "quarantine_quota": {"v_range": [["v6.0.0", ""]], "type": "integer"},
684 "drop_infected": {
685 "v_range": [["v6.0.0", ""]],
686 "type": "list",
687 "options": [
688 {"value": "imap"},
689 {"value": "smtp"},
690 {"value": "pop3"},
691 {"value": "http"},
692 {"value": "ftp"},
693 {"value": "nntp"},
694 {"value": "imaps"},
695 {"value": "smtps"},
696 {"value": "pop3s"},
697 {"value": "https"},
698 {"value": "ftps"},
699 {"value": "mapi"},
700 {"value": "cifs"},
701 {"value": "ssh", "v_range": [["v6.2.0", ""]]},
702 {"value": "mm1", "v_range": [["v6.0.0", "v6.2.7"]]},
703 {"value": "mm3", "v_range": [["v6.0.0", "v6.2.7"]]},
704 {"value": "mm4", "v_range": [["v6.0.0", "v6.2.7"]]},
705 {"value": "mm7", "v_range": [["v6.0.0", "v6.2.7"]]},
706 ],
707 "multiple_values": True,
708 "elements": "str",
709 },
710 "store_infected": {
711 "v_range": [["v6.0.0", ""]],
712 "type": "list",
713 "options": [
714 {"value": "imap"},
715 {"value": "smtp"},
716 {"value": "pop3"},
717 {"value": "http"},
718 {"value": "ftp"},
719 {"value": "nntp"},
720 {"value": "imaps"},
721 {"value": "smtps"},
722 {"value": "pop3s"},
723 {"value": "https"},
724 {"value": "ftps"},
725 {"value": "mapi"},
726 {"value": "cifs"},
727 {"value": "ssh", "v_range": [["v6.2.0", ""]]},
728 {"value": "mm1", "v_range": [["v6.0.0", "v6.2.7"]]},
729 {"value": "mm3", "v_range": [["v6.0.0", "v6.2.7"]]},
730 {"value": "mm4", "v_range": [["v6.0.0", "v6.2.7"]]},
731 {"value": "mm7", "v_range": [["v6.0.0", "v6.2.7"]]},
732 ],
733 "multiple_values": True,
734 "elements": "str",
735 },
736 "drop_machine_learning": {
737 "v_range": [["v7.0.1", ""]],
738 "type": "list",
739 "options": [
740 {"value": "imap"},
741 {"value": "smtp"},
742 {"value": "pop3"},
743 {"value": "http"},
744 {"value": "ftp"},
745 {"value": "nntp"},
746 {"value": "imaps"},
747 {"value": "smtps"},
748 {"value": "pop3s"},
749 {"value": "https"},
750 {"value": "ftps"},
751 {"value": "mapi"},
752 {"value": "cifs"},
753 {"value": "ssh"},
754 ],
755 "multiple_values": True,
756 "elements": "str",
757 },
758 "store_machine_learning": {
759 "v_range": [["v7.0.1", ""]],
760 "type": "list",
761 "options": [
762 {"value": "imap"},
763 {"value": "smtp"},
764 {"value": "pop3"},
765 {"value": "http"},
766 {"value": "ftp"},
767 {"value": "nntp"},
768 {"value": "imaps"},
769 {"value": "smtps"},
770 {"value": "pop3s"},
771 {"value": "https"},
772 {"value": "ftps"},
773 {"value": "mapi"},
774 {"value": "cifs"},
775 {"value": "ssh"},
776 ],
777 "multiple_values": True,
778 "elements": "str",
779 },
780 "lowspace": {
781 "v_range": [["v6.0.0", ""]],
782 "type": "string",
783 "options": [{"value": "drop-new"}, {"value": "ovrw-old"}],
784 },
785 "destination": {
786 "v_range": [["v6.0.0", ""]],
787 "type": "string",
788 "options": [
789 {"value": "NULL"},
790 {"value": "disk"},
791 {"value": "FortiAnalyzer"},
792 ],
793 },
794 "drop_blocked": {
795 "v_range": [["v6.0.0", "v7.4.0"]],
796 "type": "list",
797 "options": [
798 {"value": "imap"},
799 {"value": "smtp"},
800 {"value": "pop3"},
801 {"value": "http"},
802 {"value": "ftp"},
803 {"value": "nntp"},
804 {"value": "imaps"},
805 {"value": "smtps"},
806 {"value": "pop3s"},
807 {"value": "https", "v_range": [["v7.4.0", "v7.4.0"]]},
808 {"value": "ftps"},
809 {"value": "mapi"},
810 {"value": "cifs"},
811 {"value": "ssh", "v_range": [["v6.2.0", "v7.4.0"]]},
812 {"value": "mm1", "v_range": [["v6.0.0", "v6.2.7"]]},
813 {"value": "mm3", "v_range": [["v6.0.0", "v6.2.7"]]},
814 {"value": "mm4", "v_range": [["v6.0.0", "v6.2.7"]]},
815 {"value": "mm7", "v_range": [["v6.0.0", "v6.2.7"]]},
816 ],
817 "multiple_values": True,
818 "elements": "str",
819 },
820 "store_blocked": {
821 "v_range": [["v6.0.0", "v7.4.0"]],
822 "type": "list",
823 "options": [
824 {"value": "imap"},
825 {"value": "smtp"},
826 {"value": "pop3"},
827 {"value": "http"},
828 {"value": "ftp"},
829 {"value": "nntp"},
830 {"value": "imaps"},
831 {"value": "smtps"},
832 {"value": "pop3s"},
833 {"value": "https", "v_range": [["v7.4.0", "v7.4.0"]]},
834 {"value": "ftps"},
835 {"value": "mapi"},
836 {"value": "cifs"},
837 {"value": "ssh", "v_range": [["v6.2.0", "v7.4.0"]]},
838 {"value": "mm1", "v_range": [["v6.0.0", "v6.2.7"]]},
839 {"value": "mm3", "v_range": [["v6.0.0", "v6.2.7"]]},
840 {"value": "mm4", "v_range": [["v6.0.0", "v6.2.7"]]},
841 {"value": "mm7", "v_range": [["v6.0.0", "v6.2.7"]]},
842 ],
843 "multiple_values": True,
844 "elements": "str",
845 },
846 "drop_heuristic": {
847 "v_range": [["v6.0.0", "v7.0.0"]],
848 "type": "list",
849 "options": [
850 {"value": "imap"},
851 {"value": "smtp"},
852 {"value": "pop3"},
853 {"value": "http"},
854 {"value": "ftp"},
855 {"value": "nntp"},
856 {"value": "imaps"},
857 {"value": "smtps"},
858 {"value": "pop3s"},
859 {"value": "https"},
860 {"value": "ftps"},
861 {"value": "mapi"},
862 {"value": "cifs"},
863 {"value": "ssh", "v_range": [["v6.2.0", "v7.0.0"]]},
864 {"value": "mm1", "v_range": [["v6.0.0", "v6.2.7"]]},
865 {"value": "mm3", "v_range": [["v6.0.0", "v6.2.7"]]},
866 {"value": "mm4", "v_range": [["v6.0.0", "v6.2.7"]]},
867 {"value": "mm7", "v_range": [["v6.0.0", "v6.2.7"]]},
868 ],
869 "multiple_values": True,
870 "elements": "str",
871 },
872 "store_heuristic": {
873 "v_range": [["v6.0.0", "v7.0.0"]],
874 "type": "list",
875 "options": [
876 {"value": "imap"},
877 {"value": "smtp"},
878 {"value": "pop3"},
879 {"value": "http"},
880 {"value": "ftp"},
881 {"value": "nntp"},
882 {"value": "imaps"},
883 {"value": "smtps"},
884 {"value": "pop3s"},
885 {"value": "https"},
886 {"value": "ftps"},
887 {"value": "mapi"},
888 {"value": "cifs"},
889 {"value": "ssh", "v_range": [["v6.2.0", "v7.0.0"]]},
890 {"value": "mm1", "v_range": [["v6.0.0", "v6.2.7"]]},
891 {"value": "mm3", "v_range": [["v6.0.0", "v6.2.7"]]},
892 {"value": "mm4", "v_range": [["v6.0.0", "v6.2.7"]]},
893 {"value": "mm7", "v_range": [["v6.0.0", "v6.2.7"]]},
894 ],
895 "multiple_values": True,
896 "elements": "str",
897 },
898 "drop_intercepted": {
899 "v_range": [["v6.0.0", "v6.2.7"]],
900 "type": "list",
901 "options": [
902 {"value": "imap"},
903 {"value": "smtp"},
904 {"value": "pop3"},
905 {"value": "http"},
906 {"value": "ftp"},
907 {"value": "imaps"},
908 {"value": "smtps"},
909 {"value": "pop3s"},
910 {"value": "https"},
911 {"value": "ftps"},
912 {"value": "mapi"},
913 {"value": "mm1"},
914 {"value": "mm3"},
915 {"value": "mm4"},
916 {"value": "mm7"},
917 ],
918 "multiple_values": True,
919 "elements": "str",
920 },
921 "store_intercepted": {
922 "v_range": [["v6.0.0", "v6.2.7"]],
923 "type": "list",
924 "options": [
925 {"value": "imap"},
926 {"value": "smtp"},
927 {"value": "pop3"},
928 {"value": "http"},
929 {"value": "ftp"},
930 {"value": "imaps"},
931 {"value": "smtps"},
932 {"value": "pop3s"},
933 {"value": "https"},
934 {"value": "ftps"},
935 {"value": "mapi"},
936 {"value": "mm1"},
937 {"value": "mm3"},
938 {"value": "mm4"},
939 {"value": "mm7"},
940 ],
941 "multiple_values": True,
942 "elements": "str",
943 },
944 },
945 }
946
947
948 def main():
949 module_spec = schema_to_module_spec(versioned_schema)
950 mkeyname = None
951 fields = {
952 "access_token": {"required": False, "type": "str", "no_log": True},
953 "enable_log": {"required": False, "type": "bool", "default": False},
954 "vdom": {"required": False, "type": "str", "default": "root"},
955 "member_path": {"required": False, "type": "str"},
956 "member_state": {
957 "type": "str",
958 "required": False,
959 "choices": ["present", "absent"],
960 },
961 "antivirus_quarantine": {
962 "required": False,
963 "type": "dict",
964 "default": None,
965 "options": {},
966 },
967 }
968 for attribute_name in module_spec["options"]:
969 fields["antivirus_quarantine"]["options"][attribute_name] = module_spec[
970 "options"
971 ][attribute_name]
972 if mkeyname and mkeyname == attribute_name:
973 fields["antivirus_quarantine"]["options"][attribute_name]["required"] = True
974
975 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
976 check_legacy_fortiosapi(module)
977
978 is_error = False
979 has_changed = False
980 result = None
981 diff = None
982
983 versions_check_result = None
984 if module._socket_path:
985 connection = Connection(module._socket_path)
986 if "access_token" in module.params:
987 connection.set_custom_option("access_token", module.params["access_token"])
988
989 if "enable_log" in module.params:
990 connection.set_custom_option("enable_log", module.params["enable_log"])
991 else:
992 connection.set_custom_option("enable_log", False)
993 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
994 versions_check_result = check_schema_versioning(
995 fos, versioned_schema, "antivirus_quarantine"
996 )
997
998 is_error, has_changed, result, diff = fortios_antivirus(
999 module.params, fos, module.check_mode
1000 )
1001
1002 else:
1003 module.fail_json(**FAIL_SOCKET_MSG)
1004
1005 if versions_check_result and versions_check_result["matched"] is False:
1006 module.warn(
1007 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
1008 )
1009
1010 if not is_error:
1011 if versions_check_result and versions_check_result["matched"] is False:
1012 module.exit_json(
1013 changed=has_changed,
1014 version_check_warning=versions_check_result,
1015 meta=result,
1016 diff=diff,
1017 )
1018 else:
1019 module.exit_json(changed=has_changed, meta=result, diff=diff)
1020 else:
1021 if versions_check_result and versions_check_result["matched"] is False:
1022 module.fail_json(
1023 msg="Error in repo",
1024 version_check_warning=versions_check_result,
1025 meta=result,
1026 )
1027 else:
1028 module.fail_json(msg="Error in repo", meta=result)
1029
1030
1031 if __name__ == "__main__":
1032 main()