Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_system_csf.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_system_csf
23 short_description: Add this FortiGate to a Security Fabric or set up a new Security Fabric on this FortiGate 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 system feature and csf 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 system_csf:
80 description:
81 - Add this FortiGate to a Security Fabric or set up a new Security Fabric on this FortiGate.
82 default: null
83 type: dict
84 suboptions:
85 accept_auth_by_cert:
86 description:
87 - Accept connections with unknown certificates and ask admin for approval.
88 type: str
89 choices:
90 - 'disable'
91 - 'enable'
92 authorization_request_type:
93 description:
94 - Authorization request type.
95 type: str
96 choices:
97 - 'serial'
98 - 'certificate'
99 certificate:
100 description:
101 - Certificate. Source certificate.local.name.
102 type: str
103 configuration_sync:
104 description:
105 - Configuration sync mode.
106 type: str
107 choices:
108 - 'default'
109 - 'local'
110 downstream_access:
111 description:
112 - Enable/disable downstream device access to this device"s configuration and data.
113 type: str
114 choices:
115 - 'enable'
116 - 'disable'
117 downstream_accprofile:
118 description:
119 - Default access profile for requests from downstream devices. Source system.accprofile.name.
120 type: str
121 fabric_connector:
122 description:
123 - Fabric connector configuration.
124 type: list
125 elements: dict
126 suboptions:
127 accprofile:
128 description:
129 - Override access profile. Source system.accprofile.name.
130 type: str
131 configuration_write_access:
132 description:
133 - Enable/disable downstream device write access to configuration.
134 type: str
135 choices:
136 - 'enable'
137 - 'disable'
138 serial:
139 description:
140 - Serial.
141 required: true
142 type: str
143 vdom:
144 description:
145 - Virtual domains that the connector has access to. If none are set, the connector will only have access to the VDOM that it joins
146 the Security Fabric through.
147 type: list
148 elements: dict
149 suboptions:
150 name:
151 description:
152 - Virtual domain name. Source system.vdom.name.
153 required: true
154 type: str
155 fabric_device:
156 description:
157 - Fabric device configuration.
158 type: list
159 elements: dict
160 suboptions:
161 access_token:
162 description:
163 - Device access token.
164 type: str
165 device_ip:
166 description:
167 - Device IP.
168 type: str
169 device_type:
170 description:
171 - Device type.
172 type: str
173 choices:
174 - 'fortimail'
175 https_port:
176 description:
177 - HTTPS port for fabric device.
178 type: int
179 login:
180 description:
181 - Device login name.
182 type: str
183 name:
184 description:
185 - Device name.
186 required: true
187 type: str
188 password:
189 description:
190 - Device login password.
191 type: str
192 fabric_object_unification:
193 description:
194 - Fabric CMDB Object Unification.
195 type: str
196 choices:
197 - 'default'
198 - 'local'
199 fabric_workers:
200 description:
201 - Number of worker processes for Security Fabric daemon.
202 type: int
203 file_mgmt:
204 description:
205 - Enable/disable Security Fabric daemon file management.
206 type: str
207 choices:
208 - 'enable'
209 - 'disable'
210 file_quota:
211 description:
212 - Maximum amount of memory that can be used by the daemon files (in bytes).
213 type: int
214 file_quota_warning:
215 description:
216 - Warn when the set percentage of quota has been used.
217 type: int
218 fixed_key:
219 description:
220 - Auto-generated fixed key used when this device is the root. (Will automatically be generated if not set.)
221 type: str
222 forticloud_account_enforcement:
223 description:
224 - Fabric FortiCloud account unification.
225 type: str
226 choices:
227 - 'enable'
228 - 'disable'
229 group_name:
230 description:
231 - Security Fabric group name. All FortiGates in a Security Fabric must have the same group name.
232 type: str
233 group_password:
234 description:
235 - Security Fabric group password. For legacy authentication, fabric members must have the same group password.
236 type: str
237 legacy_authentication:
238 description:
239 - Enable/disable legacy authentication.
240 type: str
241 choices:
242 - 'disable'
243 - 'enable'
244 log_unification:
245 description:
246 - Enable/disable broadcast of discovery messages for log unification.
247 type: str
248 choices:
249 - 'disable'
250 - 'enable'
251 management_ip:
252 description:
253 - Management IP address of this FortiGate. Used to log into this FortiGate from another FortiGate in the Security Fabric.
254 type: str
255 management_port:
256 description:
257 - Overriding port for management connection (Overrides admin port).
258 type: int
259 saml_configuration_sync:
260 description:
261 - SAML setting configuration synchronization.
262 type: str
263 choices:
264 - 'default'
265 - 'local'
266 source_ip:
267 description:
268 - Source IP address for communication with the upstream FortiGate.
269 type: str
270 status:
271 description:
272 - Enable/disable Security Fabric.
273 type: str
274 choices:
275 - 'enable'
276 - 'disable'
277 trusted_list:
278 description:
279 - Pre-authorized and blocked security fabric nodes.
280 type: list
281 elements: dict
282 suboptions:
283 action:
284 description:
285 - Security fabric authorization action.
286 type: str
287 choices:
288 - 'accept'
289 - 'deny'
290 authorization_type:
291 description:
292 - Authorization type.
293 type: str
294 choices:
295 - 'serial'
296 - 'certificate'
297 certificate:
298 description:
299 - Certificate.
300 type: str
301 downstream_authorization:
302 description:
303 - Trust authorizations by this node"s administrator.
304 type: str
305 choices:
306 - 'enable'
307 - 'disable'
308 ha_members:
309 description:
310 - HA members.
311 type: list
312 elements: str
313 index:
314 description:
315 - Index of the downstream in tree.
316 type: int
317 name:
318 description:
319 - Name.
320 required: true
321 type: str
322 serial:
323 description:
324 - Serial.
325 type: str
326 uid:
327 description:
328 - Unique ID of the current CSF node
329 type: str
330 upstream:
331 description:
332 - IP/FQDN of the FortiGate upstream from this FortiGate in the Security Fabric.
333 type: str
334 upstream_interface:
335 description:
336 - Specify outgoing interface to reach server. Source system.interface.name.
337 type: str
338 upstream_interface_select_method:
339 description:
340 - Specify how to select outgoing interface to reach server.
341 type: str
342 choices:
343 - 'auto'
344 - 'sdwan'
345 - 'specify'
346 upstream_ip:
347 description:
348 - IP address of the FortiGate upstream from this FortiGate in the Security Fabric.
349 type: str
350 upstream_port:
351 description:
352 - The port number to use to communicate with the FortiGate upstream from this FortiGate in the Security Fabric .
353 type: int
354 """
355
356 EXAMPLES = """
357 - name: Add this FortiGate to a Security Fabric or set up a new Security Fabric on this FortiGate.
358 fortinet.fortios.fortios_system_csf:
359 vdom: "{{ vdom }}"
360 system_csf:
361 accept_auth_by_cert: "disable"
362 authorization_request_type: "serial"
363 certificate: "<your_own_value> (source certificate.local.name)"
364 configuration_sync: "default"
365 downstream_access: "enable"
366 downstream_accprofile: "<your_own_value> (source system.accprofile.name)"
367 fabric_connector:
368 -
369 accprofile: "<your_own_value> (source system.accprofile.name)"
370 configuration_write_access: "enable"
371 serial: "<your_own_value>"
372 vdom:
373 -
374 name: "default_name_14 (source system.vdom.name)"
375 fabric_device:
376 -
377 access_token: "<your_own_value>"
378 device_ip: "<your_own_value>"
379 device_type: "fortimail"
380 https_port: "443"
381 login: "<your_own_value>"
382 name: "default_name_21"
383 password: "<your_own_value>"
384 fabric_object_unification: "default"
385 fabric_workers: "2"
386 file_mgmt: "enable"
387 file_quota: "0"
388 file_quota_warning: "90"
389 fixed_key: "<your_own_value>"
390 forticloud_account_enforcement: "enable"
391 group_name: "<your_own_value>"
392 group_password: "<your_own_value>"
393 legacy_authentication: "disable"
394 log_unification: "disable"
395 management_ip: "<your_own_value>"
396 management_port: "32767"
397 saml_configuration_sync: "default"
398 source_ip: "84.230.14.43"
399 status: "enable"
400 trusted_list:
401 -
402 action: "accept"
403 authorization_type: "serial"
404 certificate: "<your_own_value>"
405 downstream_authorization: "enable"
406 ha_members: "<your_own_value>"
407 index: "0"
408 name: "default_name_46"
409 serial: "<your_own_value>"
410 uid: "<your_own_value>"
411 upstream: "<your_own_value>"
412 upstream_interface: "<your_own_value> (source system.interface.name)"
413 upstream_interface_select_method: "auto"
414 upstream_ip: "<your_own_value>"
415 upstream_port: "8013"
416 """
417
418 RETURN = """
419 build:
420 description: Build number of the fortigate image
421 returned: always
422 type: str
423 sample: '1547'
424 http_method:
425 description: Last method used to provision the content into FortiGate
426 returned: always
427 type: str
428 sample: 'PUT'
429 http_status:
430 description: Last result given by FortiGate on last operation applied
431 returned: always
432 type: str
433 sample: "200"
434 mkey:
435 description: Master key (id) used in the last call to FortiGate
436 returned: success
437 type: str
438 sample: "id"
439 name:
440 description: Name of the table used to fulfill the request
441 returned: always
442 type: str
443 sample: "urlfilter"
444 path:
445 description: Path of the table used to fulfill the request
446 returned: always
447 type: str
448 sample: "webfilter"
449 revision:
450 description: Internal revision number
451 returned: always
452 type: str
453 sample: "17.0.2.10658"
454 serial:
455 description: Serial number of the unit
456 returned: always
457 type: str
458 sample: "FGVMEVYYQT3AB5352"
459 status:
460 description: Indication of the operation's result
461 returned: always
462 type: str
463 sample: "success"
464 vdom:
465 description: Virtual domain used
466 returned: always
467 type: str
468 sample: "root"
469 version:
470 description: Version of the FortiGate
471 returned: always
472 type: str
473 sample: "v5.6.3"
474 """
475 from ansible.module_utils.basic import AnsibleModule
476 from ansible.module_utils.connection import Connection
477 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
478 FortiOSHandler,
479 )
480 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
481 check_legacy_fortiosapi,
482 )
483 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
484 schema_to_module_spec,
485 )
486 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
487 check_schema_versioning,
488 )
489 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
490 FAIL_SOCKET_MSG,
491 )
492 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
493 remove_invalid_fields,
494 )
495 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
496 is_same_comparison,
497 )
498 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
499 serialize,
500 )
501 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
502 find_current_values,
503 )
504 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
505 unify_data_format,
506 )
507
508
509 def filter_system_csf_data(json):
510 option_list = [
511 "accept_auth_by_cert",
512 "authorization_request_type",
513 "certificate",
514 "configuration_sync",
515 "downstream_access",
516 "downstream_accprofile",
517 "fabric_connector",
518 "fabric_device",
519 "fabric_object_unification",
520 "fabric_workers",
521 "file_mgmt",
522 "file_quota",
523 "file_quota_warning",
524 "fixed_key",
525 "forticloud_account_enforcement",
526 "group_name",
527 "group_password",
528 "legacy_authentication",
529 "log_unification",
530 "management_ip",
531 "management_port",
532 "saml_configuration_sync",
533 "source_ip",
534 "status",
535 "trusted_list",
536 "uid",
537 "upstream",
538 "upstream_interface",
539 "upstream_interface_select_method",
540 "upstream_ip",
541 "upstream_port",
542 ]
543
544 json = remove_invalid_fields(json)
545 dictionary = {}
546
547 for attribute in option_list:
548 if attribute in json and json[attribute] is not None:
549 dictionary[attribute] = json[attribute]
550
551 return dictionary
552
553
554 def flatten_single_path(data, path, index):
555 if (
556 not data
557 or index == len(path)
558 or path[index] not in data
559 or (not data[path[index]] and not isinstance(data[path[index]], list))
560 ):
561 return
562
563 if index == len(path) - 1:
564 data[path[index]] = " ".join(str(elem) for elem in data[path[index]])
565 if len(data[path[index]]) == 0:
566 data[path[index]] = None
567 elif isinstance(data[path[index]], list):
568 for value in data[path[index]]:
569 flatten_single_path(value, path, index + 1)
570 else:
571 flatten_single_path(data[path[index]], path, index + 1)
572
573
574 def flatten_multilists_attributes(data):
575 multilist_attrs = [
576 ["trusted_list", "ha_members"],
577 ]
578
579 for attr in multilist_attrs:
580 flatten_single_path(data, attr, 0)
581
582 return data
583
584
585 def underscore_to_hyphen(data):
586 new_data = None
587 if isinstance(data, list):
588 new_data = []
589 for i, elem in enumerate(data):
590 new_data.append(underscore_to_hyphen(elem))
591 elif isinstance(data, dict):
592 new_data = {}
593 for k, v in data.items():
594 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
595 else:
596 return data
597 return new_data
598
599
600 def system_csf(data, fos, check_mode=False):
601
602 state = None
603 vdom = data["vdom"]
604 parameters = None
605 state = data.get("state", None)
606 system_csf_data = data["system_csf"]
607
608 filtered_data = filter_system_csf_data(system_csf_data)
609 filtered_data = flatten_multilists_attributes(filtered_data)
610 converted_data = underscore_to_hyphen(filtered_data)
611
612 # check_mode starts from here
613 if check_mode:
614 diff = {
615 "before": "",
616 "after": filtered_data,
617 }
618 mkeyname = fos.get_mkeyname(None, None)
619 mkey = fos.get_mkey("system", "csf", filtered_data, vdom=vdom)
620 current_data = fos.get(
621 "system", "csf", vdom=vdom, mkey=mkey, parameters=parameters
622 )
623 is_existed = (
624 current_data
625 and current_data.get("http_status") == 200
626 and (
627 mkeyname
628 and isinstance(current_data.get("results"), list)
629 and len(current_data["results"]) > 0
630 or not mkeyname
631 and current_data["results"] # global object response
632 )
633 )
634
635 # 2. if it exists and the state is 'present' then compare current settings with desired
636 if state == "present" or state is True or state is None:
637 # for non global modules, mkeyname must exist and it's a new module when mkey is None
638 if mkeyname is not None and mkey is None:
639 return False, True, filtered_data, diff
640
641 # if mkey exists then compare each other
642 # record exits and they're matched or not
643 copied_filtered_data = filtered_data.copy()
644 copied_filtered_data.pop(mkeyname, None)
645 unified_filtered_data = unify_data_format(copied_filtered_data)
646
647 current_data_results = current_data.get("results", {})
648 current_config = (
649 current_data_results[0]
650 if mkeyname
651 and isinstance(current_data_results, list)
652 and len(current_data_results) > 0
653 else current_data_results
654 )
655 if is_existed:
656 unified_current_values = find_current_values(
657 unified_filtered_data,
658 unify_data_format(current_config),
659 )
660
661 is_same = is_same_comparison(
662 serialize(unified_current_values), serialize(unified_filtered_data)
663 )
664
665 return (
666 False,
667 not is_same,
668 filtered_data,
669 {"before": unified_current_values, "after": unified_filtered_data},
670 )
671
672 # record does not exist
673 return False, True, filtered_data, diff
674
675 if state == "absent":
676 if mkey is None:
677 return (
678 False,
679 False,
680 filtered_data,
681 {"before": current_data["results"][0], "after": ""},
682 )
683
684 if is_existed:
685 return (
686 False,
687 True,
688 filtered_data,
689 {"before": current_data["results"][0], "after": ""},
690 )
691 return False, False, filtered_data, {}
692
693 return True, False, {"reason: ": "Must provide state parameter"}, {}
694 # pass post processed data to member operations
695 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
696 data_copy = data.copy()
697 data_copy["system_csf"] = filtered_data
698 fos.do_member_operation(
699 "system",
700 "csf",
701 data_copy,
702 )
703
704 return fos.set(
705 "system", "csf", data=converted_data, vdom=vdom, parameters=parameters
706 )
707
708
709 def is_successful_status(resp):
710 return (
711 "status" in resp
712 and resp["status"] == "success"
713 or "http_status" in resp
714 and resp["http_status"] == 200
715 or "http_method" in resp
716 and resp["http_method"] == "DELETE"
717 and resp["http_status"] == 404
718 )
719
720
721 def fortios_system(data, fos, check_mode):
722
723 if data["system_csf"]:
724 resp = system_csf(data, fos, check_mode)
725 else:
726 fos._module.fail_json(msg="missing task body: %s" % ("system_csf"))
727 if isinstance(resp, tuple) and len(resp) == 4:
728 return resp
729 return (
730 not is_successful_status(resp),
731 is_successful_status(resp)
732 and (resp["revision_changed"] if "revision_changed" in resp else True),
733 resp,
734 {},
735 )
736
737
738 versioned_schema = {
739 "v_range": [["v6.0.0", ""]],
740 "type": "dict",
741 "children": {
742 "status": {
743 "v_range": [["v6.0.0", ""]],
744 "type": "string",
745 "options": [{"value": "enable"}, {"value": "disable"}],
746 },
747 "uid": {"v_range": [["v7.4.2", ""]], "type": "string"},
748 "upstream": {"v_range": [["v7.0.2", ""]], "type": "string"},
749 "source_ip": {"v_range": [["v7.4.4", ""]], "type": "string"},
750 "upstream_interface_select_method": {
751 "v_range": [["v7.4.4", ""]],
752 "type": "string",
753 "options": [{"value": "auto"}, {"value": "sdwan"}, {"value": "specify"}],
754 },
755 "upstream_interface": {"v_range": [["v7.4.4", ""]], "type": "string"},
756 "upstream_port": {"v_range": [["v6.0.0", ""]], "type": "integer"},
757 "group_name": {"v_range": [["v6.0.0", ""]], "type": "string"},
758 "group_password": {"v_range": [["v6.0.0", ""]], "type": "string"},
759 "accept_auth_by_cert": {
760 "v_range": [["v6.4.0", "v6.4.0"], ["v6.4.4", ""]],
761 "type": "string",
762 "options": [{"value": "disable"}, {"value": "enable"}],
763 },
764 "log_unification": {
765 "v_range": [["v7.0.0", ""]],
766 "type": "string",
767 "options": [{"value": "disable"}, {"value": "enable"}],
768 },
769 "authorization_request_type": {
770 "v_range": [["v6.4.0", "v6.4.0"], ["v6.4.4", ""]],
771 "type": "string",
772 "options": [{"value": "serial"}, {"value": "certificate"}],
773 },
774 "certificate": {
775 "v_range": [["v6.4.0", "v6.4.0"], ["v6.4.4", ""]],
776 "type": "string",
777 },
778 "fabric_workers": {"v_range": [["v6.4.4", ""]], "type": "integer"},
779 "downstream_access": {
780 "v_range": [["v7.0.0", ""]],
781 "type": "string",
782 "options": [{"value": "enable"}, {"value": "disable"}],
783 },
784 "legacy_authentication": {
785 "v_range": [["v7.6.1", ""]],
786 "type": "string",
787 "options": [{"value": "disable"}, {"value": "enable"}],
788 },
789 "downstream_accprofile": {"v_range": [["v7.0.0", ""]], "type": "string"},
790 "configuration_sync": {
791 "v_range": [["v6.0.0", ""]],
792 "type": "string",
793 "options": [{"value": "default"}, {"value": "local"}],
794 },
795 "fabric_object_unification": {
796 "v_range": [["v6.4.0", ""]],
797 "type": "string",
798 "options": [{"value": "default"}, {"value": "local"}],
799 },
800 "saml_configuration_sync": {
801 "v_range": [["v6.4.0", "v6.4.0"], ["v6.4.4", ""]],
802 "type": "string",
803 "options": [{"value": "default"}, {"value": "local"}],
804 },
805 "trusted_list": {
806 "type": "list",
807 "elements": "dict",
808 "children": {
809 "name": {
810 "v_range": [["v6.4.0", "v6.4.0"], ["v6.4.4", ""]],
811 "type": "string",
812 "required": True,
813 },
814 "authorization_type": {
815 "v_range": [["v6.4.0", "v6.4.0"], ["v6.4.4", ""]],
816 "type": "string",
817 "options": [{"value": "serial"}, {"value": "certificate"}],
818 },
819 "serial": {"v_range": [["v6.0.0", ""]], "type": "string"},
820 "certificate": {
821 "v_range": [["v6.4.0", "v6.4.0"], ["v6.4.4", ""]],
822 "type": "string",
823 },
824 "action": {
825 "v_range": [["v6.0.0", ""]],
826 "type": "string",
827 "options": [{"value": "accept"}, {"value": "deny"}],
828 },
829 "ha_members": {
830 "v_range": [["v6.0.0", ""]],
831 "type": "list",
832 "multiple_values": True,
833 "elements": "str",
834 },
835 "downstream_authorization": {
836 "v_range": [["v6.0.0", ""]],
837 "type": "string",
838 "options": [{"value": "enable"}, {"value": "disable"}],
839 },
840 "index": {"v_range": [["v7.2.4", ""]], "type": "integer"},
841 },
842 "v_range": [["v6.0.0", ""]],
843 },
844 "fabric_connector": {
845 "type": "list",
846 "elements": "dict",
847 "children": {
848 "serial": {
849 "v_range": [["v7.0.0", ""]],
850 "type": "string",
851 "required": True,
852 },
853 "accprofile": {"v_range": [["v7.0.0", ""]], "type": "string"},
854 "configuration_write_access": {
855 "v_range": [["v7.0.0", ""]],
856 "type": "string",
857 "options": [{"value": "enable"}, {"value": "disable"}],
858 },
859 "vdom": {
860 "type": "list",
861 "elements": "dict",
862 "children": {
863 "name": {
864 "v_range": [["v7.4.0", ""]],
865 "type": "string",
866 "required": True,
867 }
868 },
869 "v_range": [["v7.4.0", ""]],
870 },
871 },
872 "v_range": [["v7.0.0", ""]],
873 },
874 "forticloud_account_enforcement": {
875 "v_range": [["v7.0.4", ""]],
876 "type": "string",
877 "options": [{"value": "enable"}, {"value": "disable"}],
878 },
879 "file_mgmt": {
880 "v_range": [["v7.4.0", ""]],
881 "type": "string",
882 "options": [{"value": "enable"}, {"value": "disable"}],
883 },
884 "file_quota": {"v_range": [["v7.4.0", ""]], "type": "integer"},
885 "file_quota_warning": {"v_range": [["v7.4.0", ""]], "type": "integer"},
886 "fabric_device": {
887 "type": "list",
888 "elements": "dict",
889 "children": {
890 "name": {
891 "v_range": [["v6.0.0", "v7.0.12"]],
892 "type": "string",
893 "required": True,
894 },
895 "device_ip": {"v_range": [["v6.0.0", "v7.0.12"]], "type": "string"},
896 "https_port": {"v_range": [["v6.2.0", "v7.0.12"]], "type": "integer"},
897 "access_token": {"v_range": [["v6.2.0", "v7.0.12"]], "type": "string"},
898 "device_type": {
899 "v_range": [["v6.0.0", "v6.0.11"]],
900 "type": "string",
901 "options": [{"value": "fortimail"}],
902 },
903 "login": {"v_range": [["v6.0.0", "v6.0.11"]], "type": "string"},
904 "password": {"v_range": [["v6.0.0", "v6.0.11"]], "type": "string"},
905 },
906 "v_range": [["v6.0.0", "v7.0.12"]],
907 },
908 "upstream_ip": {"v_range": [["v6.0.0", "v7.0.1"]], "type": "string"},
909 "management_ip": {"v_range": [["v6.0.0", "v6.4.4"]], "type": "string"},
910 "management_port": {"v_range": [["v6.0.0", "v6.4.4"]], "type": "integer"},
911 "fixed_key": {
912 "v_range": [["v6.0.0", "v6.0.11"], ["v6.2.3", "v6.2.3"]],
913 "type": "string",
914 },
915 },
916 }
917
918
919 def main():
920 module_spec = schema_to_module_spec(versioned_schema)
921 mkeyname = None
922 fields = {
923 "access_token": {"required": False, "type": "str", "no_log": True},
924 "enable_log": {"required": False, "type": "bool", "default": False},
925 "vdom": {"required": False, "type": "str", "default": "root"},
926 "member_path": {"required": False, "type": "str"},
927 "member_state": {
928 "type": "str",
929 "required": False,
930 "choices": ["present", "absent"],
931 },
932 "system_csf": {
933 "required": False,
934 "type": "dict",
935 "default": None,
936 "options": {},
937 },
938 }
939 for attribute_name in module_spec["options"]:
940 fields["system_csf"]["options"][attribute_name] = module_spec["options"][
941 attribute_name
942 ]
943 if mkeyname and mkeyname == attribute_name:
944 fields["system_csf"]["options"][attribute_name]["required"] = True
945
946 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
947 check_legacy_fortiosapi(module)
948
949 is_error = False
950 has_changed = False
951 result = None
952 diff = None
953
954 versions_check_result = None
955 if module._socket_path:
956 connection = Connection(module._socket_path)
957 if "access_token" in module.params:
958 connection.set_custom_option("access_token", module.params["access_token"])
959
960 if "enable_log" in module.params:
961 connection.set_custom_option("enable_log", module.params["enable_log"])
962 else:
963 connection.set_custom_option("enable_log", False)
964 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
965 versions_check_result = check_schema_versioning(
966 fos, versioned_schema, "system_csf"
967 )
968
969 is_error, has_changed, result, diff = fortios_system(
970 module.params, fos, module.check_mode
971 )
972
973 else:
974 module.fail_json(**FAIL_SOCKET_MSG)
975
976 if versions_check_result and versions_check_result["matched"] is False:
977 module.warn(
978 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
979 )
980
981 if not is_error:
982 if versions_check_result and versions_check_result["matched"] is False:
983 module.exit_json(
984 changed=has_changed,
985 version_check_warning=versions_check_result,
986 meta=result,
987 diff=diff,
988 )
989 else:
990 module.exit_json(changed=has_changed, meta=result, diff=diff)
991 else:
992 if versions_check_result and versions_check_result["matched"] is False:
993 module.fail_json(
994 msg="Error in repo",
995 version_check_warning=versions_check_result,
996 meta=result,
997 )
998 else:
999 module.fail_json(msg="Error in repo", meta=result)
1000
1001
1002 if __name__ == "__main__":
1003 main()