Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address6.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_firewall_address6
23 short_description: Configure IPv6 firewall addresses 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 firewall feature and address6 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 firewall_address6:
88 description:
89 - Configure IPv6 firewall addresses.
90 default: null
91 type: dict
92 suboptions:
93 cache_ttl:
94 description:
95 - Minimal TTL of individual IPv6 addresses in FQDN cache.
96 type: int
97 color:
98 description:
99 - Integer value to determine the color of the icon in the GUI (range 1 to 32).
100 type: int
101 comment:
102 description:
103 - Comment.
104 type: str
105 country:
106 description:
107 - IPv6 addresses associated to a specific country.
108 type: str
109 end_ip:
110 description:
111 - 'Final IP address (inclusive) in the range for the address (format: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx).'
112 type: str
113 end_mac:
114 description:
115 - Last MAC address in the range.
116 type: str
117 epg_name:
118 description:
119 - Endpoint group name.
120 type: str
121 fabric_object:
122 description:
123 - Security Fabric global object setting.
124 type: str
125 choices:
126 - 'enable'
127 - 'disable'
128 filter:
129 description:
130 - Match criteria filter.
131 type: str
132 fqdn:
133 description:
134 - Fully qualified domain name.
135 type: str
136 host:
137 description:
138 - Host Address.
139 type: str
140 host_type:
141 description:
142 - Host type.
143 type: str
144 choices:
145 - 'any'
146 - 'specific'
147 ip6:
148 description:
149 - 'IPv6 address prefix (format: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/xxx).'
150 type: str
151 list:
152 description:
153 - IP address list.
154 type: list
155 elements: dict
156 suboptions:
157 ip:
158 description:
159 - IP.
160 required: true
161 type: str
162 net_id:
163 description:
164 - Network ID.
165 type: str
166 obj_id:
167 description:
168 - Object ID.
169 type: str
170 macaddr:
171 description:
172 - Multiple MAC address ranges.
173 type: list
174 elements: dict
175 suboptions:
176 macaddr:
177 description:
178 - MAC address ranges <start>[-<end>] separated by space.
179 required: true
180 type: str
181 name:
182 description:
183 - Address name.
184 required: true
185 type: str
186 obj_id:
187 description:
188 - Object ID for NSX.
189 type: str
190 passive_fqdn_learning:
191 description:
192 - Enable/disable passive learning of FQDNs. When enabled, the FortiGate learns, trusts, and saves FQDNs from endpoint DNS queries .
193 type: str
194 choices:
195 - 'disable'
196 - 'enable'
197 route_tag:
198 description:
199 - route-tag address.
200 type: int
201 sdn:
202 description:
203 - SDN. Source system.sdn-connector.name.
204 type: str
205 choices:
206 - 'nsx'
207 sdn_addr_type:
208 description:
209 - Type of addresses to collect.
210 type: str
211 choices:
212 - 'private'
213 - 'public'
214 - 'all'
215 sdn_tag:
216 description:
217 - SDN Tag.
218 type: str
219 start_ip:
220 description:
221 - 'First IP address (inclusive) in the range for the address (format: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx).'
222 type: str
223 start_mac:
224 description:
225 - First MAC address in the range.
226 type: str
227 subnet_segment:
228 description:
229 - IPv6 subnet segments.
230 type: list
231 elements: dict
232 suboptions:
233 name:
234 description:
235 - Name.
236 required: true
237 type: str
238 type:
239 description:
240 - Subnet segment type.
241 type: str
242 choices:
243 - 'any'
244 - 'specific'
245 value:
246 description:
247 - Subnet segment value.
248 type: str
249 tagging:
250 description:
251 - Config object tagging.
252 type: list
253 elements: dict
254 suboptions:
255 category:
256 description:
257 - Tag category. Source system.object-tagging.category.
258 type: str
259 name:
260 description:
261 - Tagging entry name.
262 required: true
263 type: str
264 tags:
265 description:
266 - Tags.
267 type: list
268 elements: dict
269 suboptions:
270 name:
271 description:
272 - Tag name. Source system.object-tagging.tags.name.
273 required: true
274 type: str
275 template:
276 description:
277 - IPv6 address template. Source firewall.address6-template.name.
278 type: str
279 tenant:
280 description:
281 - Tenant.
282 type: str
283 type:
284 description:
285 - Type of IPv6 address object .
286 type: str
287 choices:
288 - 'ipprefix'
289 - 'iprange'
290 - 'fqdn'
291 - 'geography'
292 - 'dynamic'
293 - 'template'
294 - 'mac'
295 - 'route-tag'
296 - 'wildcard'
297 uuid:
298 description:
299 - Universally Unique Identifier (UUID; automatically assigned but can be manually reset).
300 type: str
301 visibility:
302 description:
303 - Enable/disable the visibility of the object in the GUI.
304 type: str
305 choices:
306 - 'enable'
307 - 'disable'
308 wildcard:
309 description:
310 - IPv6 address and wildcard netmask.
311 type: str
312 """
313
314 EXAMPLES = """
315 - name: Configure IPv6 firewall addresses.
316 fortinet.fortios.fortios_firewall_address6:
317 vdom: "{{ vdom }}"
318 state: "present"
319 access_token: "<your_own_value>"
320 firewall_address6:
321 cache_ttl: "0"
322 color: "0"
323 comment: "Comment."
324 country: "<your_own_value>"
325 end_ip: "<your_own_value>"
326 end_mac: "<your_own_value>"
327 epg_name: "<your_own_value>"
328 fabric_object: "enable"
329 filter: "<your_own_value>"
330 fqdn: "<your_own_value>"
331 host: "myhostname"
332 host_type: "any"
333 ip6: "<your_own_value>"
334 list:
335 -
336 ip: "<your_own_value>"
337 net_id: "<your_own_value>"
338 obj_id: "<your_own_value>"
339 macaddr:
340 -
341 macaddr: "<your_own_value>"
342 name: "default_name_22"
343 obj_id: "<your_own_value>"
344 passive_fqdn_learning: "disable"
345 route_tag: "0"
346 sdn: "nsx"
347 sdn_addr_type: "private"
348 sdn_tag: "<your_own_value>"
349 start_ip: "<your_own_value>"
350 start_mac: "<your_own_value>"
351 subnet_segment:
352 -
353 name: "default_name_32"
354 type: "any"
355 value: "<your_own_value>"
356 tagging:
357 -
358 category: "<your_own_value> (source system.object-tagging.category)"
359 name: "default_name_37"
360 tags:
361 -
362 name: "default_name_39 (source system.object-tagging.tags.name)"
363 template: "<your_own_value> (source firewall.address6-template.name)"
364 tenant: "<your_own_value>"
365 type: "ipprefix"
366 uuid: "<your_own_value>"
367 visibility: "enable"
368 wildcard: "<your_own_value>"
369 """
370
371 RETURN = """
372 build:
373 description: Build number of the fortigate image
374 returned: always
375 type: str
376 sample: '1547'
377 http_method:
378 description: Last method used to provision the content into FortiGate
379 returned: always
380 type: str
381 sample: 'PUT'
382 http_status:
383 description: Last result given by FortiGate on last operation applied
384 returned: always
385 type: str
386 sample: "200"
387 mkey:
388 description: Master key (id) used in the last call to FortiGate
389 returned: success
390 type: str
391 sample: "id"
392 name:
393 description: Name of the table used to fulfill the request
394 returned: always
395 type: str
396 sample: "urlfilter"
397 path:
398 description: Path of the table used to fulfill the request
399 returned: always
400 type: str
401 sample: "webfilter"
402 revision:
403 description: Internal revision number
404 returned: always
405 type: str
406 sample: "17.0.2.10658"
407 serial:
408 description: Serial number of the unit
409 returned: always
410 type: str
411 sample: "FGVMEVYYQT3AB5352"
412 status:
413 description: Indication of the operation's result
414 returned: always
415 type: str
416 sample: "success"
417 vdom:
418 description: Virtual domain used
419 returned: always
420 type: str
421 sample: "root"
422 version:
423 description: Version of the FortiGate
424 returned: always
425 type: str
426 sample: "v5.6.3"
427 """
428 from ansible.module_utils.basic import AnsibleModule
429 from ansible.module_utils.connection import Connection
430 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
431 FortiOSHandler,
432 )
433 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
434 check_legacy_fortiosapi,
435 )
436 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
437 schema_to_module_spec,
438 )
439 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
440 check_schema_versioning,
441 )
442 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
443 FAIL_SOCKET_MSG,
444 )
445 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
446 remove_invalid_fields,
447 )
448 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
449 is_same_comparison,
450 )
451 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
452 serialize,
453 )
454 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
455 find_current_values,
456 )
457 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
458 unify_data_format,
459 )
460
461
462 def filter_firewall_address6_data(json):
463 option_list = [
464 "cache_ttl",
465 "color",
466 "comment",
467 "country",
468 "end_ip",
469 "end_mac",
470 "epg_name",
471 "fabric_object",
472 "filter",
473 "fqdn",
474 "host",
475 "host_type",
476 "ip6",
477 "list",
478 "macaddr",
479 "name",
480 "obj_id",
481 "passive_fqdn_learning",
482 "route_tag",
483 "sdn",
484 "sdn_addr_type",
485 "sdn_tag",
486 "start_ip",
487 "start_mac",
488 "subnet_segment",
489 "tagging",
490 "template",
491 "tenant",
492 "type",
493 "uuid",
494 "visibility",
495 "wildcard",
496 ]
497
498 json = remove_invalid_fields(json)
499 dictionary = {}
500
501 for attribute in option_list:
502 if attribute in json and json[attribute] is not None:
503 dictionary[attribute] = json[attribute]
504
505 return dictionary
506
507
508 def underscore_to_hyphen(data):
509 new_data = None
510 if isinstance(data, list):
511 new_data = []
512 for i, elem in enumerate(data):
513 new_data.append(underscore_to_hyphen(elem))
514 elif isinstance(data, dict):
515 new_data = {}
516 for k, v in data.items():
517 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
518 else:
519 return data
520 return new_data
521
522
523 def firewall_address6(data, fos, check_mode=False):
524
525 state = None
526 vdom = data["vdom"]
527 parameters = None
528 state = data.get("state", None)
529 firewall_address6_data = data["firewall_address6"]
530
531 filtered_data = filter_firewall_address6_data(firewall_address6_data)
532 converted_data = underscore_to_hyphen(filtered_data)
533
534 # check_mode starts from here
535 if check_mode:
536 diff = {
537 "before": "",
538 "after": filtered_data,
539 }
540 mkeyname = fos.get_mkeyname(None, None)
541 mkey = fos.get_mkey("firewall", "address6", filtered_data, vdom=vdom)
542 current_data = fos.get(
543 "firewall", "address6", vdom=vdom, mkey=mkey, parameters=parameters
544 )
545 is_existed = (
546 current_data
547 and current_data.get("http_status") == 200
548 and (
549 mkeyname
550 and isinstance(current_data.get("results"), list)
551 and len(current_data["results"]) > 0
552 or not mkeyname
553 and current_data["results"] # global object response
554 )
555 )
556
557 # 2. if it exists and the state is 'present' then compare current settings with desired
558 if state == "present" or state is True or state is None:
559 # for non global modules, mkeyname must exist and it's a new module when mkey is None
560 if mkeyname is not None and mkey is None:
561 return False, True, filtered_data, diff
562
563 # if mkey exists then compare each other
564 # record exits and they're matched or not
565 copied_filtered_data = filtered_data.copy()
566 copied_filtered_data.pop(mkeyname, None)
567 unified_filtered_data = unify_data_format(copied_filtered_data)
568
569 current_data_results = current_data.get("results", {})
570 current_config = (
571 current_data_results[0]
572 if mkeyname
573 and isinstance(current_data_results, list)
574 and len(current_data_results) > 0
575 else current_data_results
576 )
577 if is_existed:
578 unified_current_values = find_current_values(
579 unified_filtered_data,
580 unify_data_format(current_config),
581 )
582
583 is_same = is_same_comparison(
584 serialize(unified_current_values), serialize(unified_filtered_data)
585 )
586
587 return (
588 False,
589 not is_same,
590 filtered_data,
591 {"before": unified_current_values, "after": unified_filtered_data},
592 )
593
594 # record does not exist
595 return False, True, filtered_data, diff
596
597 if state == "absent":
598 if mkey is None:
599 return (
600 False,
601 False,
602 filtered_data,
603 {"before": current_data["results"][0], "after": ""},
604 )
605
606 if is_existed:
607 return (
608 False,
609 True,
610 filtered_data,
611 {"before": current_data["results"][0], "after": ""},
612 )
613 return False, False, filtered_data, {}
614
615 return True, False, {"reason: ": "Must provide state parameter"}, {}
616 # pass post processed data to member operations
617 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
618 data_copy = data.copy()
619 data_copy["firewall_address6"] = filtered_data
620 fos.do_member_operation(
621 "firewall",
622 "address6",
623 data_copy,
624 )
625
626 if state == "present" or state is True:
627 return fos.set(
628 "firewall",
629 "address6",
630 data=converted_data,
631 vdom=vdom,
632 parameters=parameters,
633 )
634
635 elif state == "absent":
636 return fos.delete(
637 "firewall",
638 "address6",
639 mkey=converted_data["name"],
640 vdom=vdom,
641 parameters=parameters,
642 )
643 else:
644 fos._module.fail_json(msg="state must be present or absent!")
645
646
647 def is_successful_status(resp):
648 return (
649 "status" in resp
650 and resp["status"] == "success"
651 or "http_status" in resp
652 and resp["http_status"] == 200
653 or "http_method" in resp
654 and resp["http_method"] == "DELETE"
655 and resp["http_status"] == 404
656 )
657
658
659 def fortios_firewall(data, fos, check_mode):
660
661 if data["firewall_address6"]:
662 resp = firewall_address6(data, fos, check_mode)
663 else:
664 fos._module.fail_json(msg="missing task body: %s" % ("firewall_address6"))
665 if isinstance(resp, tuple) and len(resp) == 4:
666 return resp
667 return (
668 not is_successful_status(resp),
669 is_successful_status(resp)
670 and (resp["revision_changed"] if "revision_changed" in resp else True),
671 resp,
672 {},
673 )
674
675
676 versioned_schema = {
677 "type": "list",
678 "elements": "dict",
679 "children": {
680 "name": {"v_range": [["v6.0.0", ""]], "type": "string", "required": True},
681 "uuid": {"v_range": [["v6.0.0", ""]], "type": "string"},
682 "type": {
683 "v_range": [["v6.0.0", ""]],
684 "type": "string",
685 "options": [
686 {"value": "ipprefix"},
687 {"value": "iprange"},
688 {"value": "fqdn"},
689 {"value": "geography", "v_range": [["v6.4.0", ""]]},
690 {"value": "dynamic"},
691 {"value": "template"},
692 {
693 "value": "mac",
694 "v_range": [
695 ["v6.2.0", "v6.2.0"],
696 ["v6.2.5", "v6.4.0"],
697 ["v6.4.4", ""],
698 ],
699 },
700 {"value": "route-tag", "v_range": [["v7.4.0", ""]]},
701 {"value": "wildcard", "v_range": [["v7.6.4", ""]]},
702 ],
703 },
704 "route_tag": {"v_range": [["v7.4.0", ""]], "type": "integer"},
705 "macaddr": {
706 "type": "list",
707 "elements": "dict",
708 "children": {
709 "macaddr": {
710 "v_range": [["v7.0.0", ""]],
711 "type": "string",
712 "required": True,
713 }
714 },
715 "v_range": [["v7.0.0", ""]],
716 },
717 "sdn": {
718 "v_range": [["v6.0.0", ""]],
719 "type": "string",
720 "options": [{"value": "nsx", "v_range": [["v6.0.0", "v6.0.11"]]}],
721 },
722 "ip6": {"v_range": [["v6.0.0", ""]], "type": "string"},
723 "wildcard": {"v_range": [["v7.6.4", ""]], "type": "string"},
724 "start_ip": {"v_range": [["v6.0.0", ""]], "type": "string"},
725 "end_ip": {"v_range": [["v6.0.0", ""]], "type": "string"},
726 "fqdn": {"v_range": [["v6.0.0", ""]], "type": "string"},
727 "country": {"v_range": [["v6.4.0", ""]], "type": "string"},
728 "cache_ttl": {"v_range": [["v6.0.0", ""]], "type": "integer"},
729 "color": {"v_range": [["v6.0.0", ""]], "type": "integer"},
730 "obj_id": {"v_range": [["v6.0.0", ""]], "type": "string"},
731 "tagging": {
732 "type": "list",
733 "elements": "dict",
734 "children": {
735 "name": {
736 "v_range": [["v6.0.0", ""]],
737 "type": "string",
738 "required": True,
739 },
740 "category": {"v_range": [["v6.0.0", ""]], "type": "string"},
741 "tags": {
742 "type": "list",
743 "elements": "dict",
744 "children": {
745 "name": {
746 "v_range": [["v6.0.0", ""]],
747 "type": "string",
748 "required": True,
749 }
750 },
751 "v_range": [["v6.0.0", ""]],
752 },
753 },
754 "v_range": [["v6.0.0", ""]],
755 },
756 "comment": {"v_range": [["v6.0.0", ""]], "type": "string"},
757 "template": {"v_range": [["v6.0.0", ""]], "type": "string"},
758 "subnet_segment": {
759 "type": "list",
760 "elements": "dict",
761 "children": {
762 "name": {
763 "v_range": [["v6.0.0", ""]],
764 "type": "string",
765 "required": True,
766 },
767 "type": {
768 "v_range": [["v6.0.0", ""]],
769 "type": "string",
770 "options": [{"value": "any"}, {"value": "specific"}],
771 },
772 "value": {"v_range": [["v6.0.0", ""]], "type": "string"},
773 },
774 "v_range": [["v6.0.0", ""]],
775 },
776 "host_type": {
777 "v_range": [["v6.0.0", ""]],
778 "type": "string",
779 "options": [{"value": "any"}, {"value": "specific"}],
780 },
781 "host": {"v_range": [["v6.0.0", ""]], "type": "string"},
782 "tenant": {"v_range": [["v7.2.1", ""]], "type": "string"},
783 "epg_name": {"v_range": [["v7.2.1", ""]], "type": "string"},
784 "sdn_tag": {"v_range": [["v7.2.1", ""]], "type": "string"},
785 "filter": {"v_range": [["v7.6.1", ""]], "type": "string"},
786 "list": {
787 "type": "list",
788 "elements": "dict",
789 "children": {
790 "ip": {"v_range": [["v6.0.0", ""]], "type": "string", "required": True},
791 "obj_id": {"v_range": [["v6.2.3", "v6.2.3"]], "type": "string"},
792 "net_id": {"v_range": [["v6.2.3", "v6.2.3"]], "type": "string"},
793 },
794 "v_range": [["v6.0.0", ""]],
795 },
796 "sdn_addr_type": {
797 "v_range": [["v7.6.1", ""]],
798 "type": "string",
799 "options": [{"value": "private"}, {"value": "public"}, {"value": "all"}],
800 },
801 "passive_fqdn_learning": {
802 "v_range": [["v7.6.5", ""]],
803 "type": "string",
804 "options": [{"value": "disable"}, {"value": "enable"}],
805 },
806 "fabric_object": {
807 "v_range": [["v6.4.4", ""]],
808 "type": "string",
809 "options": [{"value": "enable"}, {"value": "disable"}],
810 },
811 "start_mac": {
812 "v_range": [
813 ["v6.2.0", "v6.2.0"],
814 ["v6.2.5", "v6.4.0"],
815 ["v6.4.4", "v6.4.4"],
816 ],
817 "type": "string",
818 },
819 "end_mac": {
820 "v_range": [
821 ["v6.2.0", "v6.2.0"],
822 ["v6.2.5", "v6.4.0"],
823 ["v6.4.4", "v6.4.4"],
824 ],
825 "type": "string",
826 },
827 "visibility": {
828 "v_range": [["v6.0.0", "v6.2.7"]],
829 "type": "string",
830 "options": [{"value": "enable"}, {"value": "disable"}],
831 },
832 },
833 "v_range": [["v6.0.0", ""]],
834 }
835
836
837 def main():
838 module_spec = schema_to_module_spec(versioned_schema)
839 mkeyname = "name"
840 fields = {
841 "access_token": {"required": False, "type": "str", "no_log": True},
842 "enable_log": {"required": False, "type": "bool", "default": False},
843 "vdom": {"required": False, "type": "str", "default": "root"},
844 "member_path": {"required": False, "type": "str"},
845 "member_state": {
846 "type": "str",
847 "required": False,
848 "choices": ["present", "absent"],
849 },
850 "state": {"required": True, "type": "str", "choices": ["present", "absent"]},
851 "firewall_address6": {
852 "required": False,
853 "type": "dict",
854 "default": None,
855 "options": {},
856 },
857 }
858 for attribute_name in module_spec["options"]:
859 fields["firewall_address6"]["options"][attribute_name] = module_spec["options"][
860 attribute_name
861 ]
862 if mkeyname and mkeyname == attribute_name:
863 fields["firewall_address6"]["options"][attribute_name]["required"] = True
864
865 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
866 check_legacy_fortiosapi(module)
867
868 is_error = False
869 has_changed = False
870 result = None
871 diff = None
872
873 versions_check_result = None
874 if module._socket_path:
875 connection = Connection(module._socket_path)
876 if "access_token" in module.params:
877 connection.set_custom_option("access_token", module.params["access_token"])
878
879 if "enable_log" in module.params:
880 connection.set_custom_option("enable_log", module.params["enable_log"])
881 else:
882 connection.set_custom_option("enable_log", False)
883 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
884 versions_check_result = check_schema_versioning(
885 fos, versioned_schema, "firewall_address6"
886 )
887
888 is_error, has_changed, result, diff = fortios_firewall(
889 module.params, fos, module.check_mode
890 )
891
892 else:
893 module.fail_json(**FAIL_SOCKET_MSG)
894
895 if versions_check_result and versions_check_result["matched"] is False:
896 module.warn(
897 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
898 )
899
900 if not is_error:
901 if versions_check_result and versions_check_result["matched"] is False:
902 module.exit_json(
903 changed=has_changed,
904 version_check_warning=versions_check_result,
905 meta=result,
906 diff=diff,
907 )
908 else:
909 module.exit_json(changed=has_changed, meta=result, diff=diff)
910 else:
911 if versions_check_result and versions_check_result["matched"] is False:
912 module.fail_json(
913 msg="Error in repo",
914 version_check_warning=versions_check_result,
915 meta=result,
916 )
917 else:
918 module.fail_json(msg="Error in repo", meta=result)
919
920
921 if __name__ == "__main__":
922 main()