Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_system_np6.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_np6
23 short_description: Configure NP6 attributes 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 np6 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 system_np6:
88 description:
89 - Configure NP6 attributes.
90 default: null
91 type: dict
92 suboptions:
93 fastpath:
94 description:
95 - Enable/disable NP6 offloading (also called fast path).
96 type: str
97 choices:
98 - 'disable'
99 - 'enable'
100 fp_anomaly:
101 description:
102 - NP6 IPv4 anomaly protection. trap-to-host forwards anomaly sessions to the CPU.
103 type: dict
104 suboptions:
105 icmp_csum_err:
106 description:
107 - Invalid IPv4 ICMP checksum anomalies.
108 type: str
109 choices:
110 - 'drop'
111 - 'trap-to-host'
112 icmp_frag:
113 description:
114 - Layer 3 fragmented packets that could be part of layer 4 ICMP anomalies.
115 type: str
116 choices:
117 - 'allow'
118 - 'drop'
119 - 'trap-to-host'
120 icmp_land:
121 description:
122 - ICMP land anomalies.
123 type: str
124 choices:
125 - 'allow'
126 - 'drop'
127 - 'trap-to-host'
128 ipv4_csum_err:
129 description:
130 - Invalid IPv4 IP checksum anomalies.
131 type: str
132 choices:
133 - 'drop'
134 - 'trap-to-host'
135 ipv4_land:
136 description:
137 - Land anomalies.
138 type: str
139 choices:
140 - 'allow'
141 - 'drop'
142 - 'trap-to-host'
143 ipv4_optlsrr:
144 description:
145 - Loose source record route option anomalies.
146 type: str
147 choices:
148 - 'allow'
149 - 'drop'
150 - 'trap-to-host'
151 ipv4_optrr:
152 description:
153 - Record route option anomalies.
154 type: str
155 choices:
156 - 'allow'
157 - 'drop'
158 - 'trap-to-host'
159 ipv4_optsecurity:
160 description:
161 - Security option anomalies.
162 type: str
163 choices:
164 - 'allow'
165 - 'drop'
166 - 'trap-to-host'
167 ipv4_optssrr:
168 description:
169 - Strict source record route option anomalies.
170 type: str
171 choices:
172 - 'allow'
173 - 'drop'
174 - 'trap-to-host'
175 ipv4_optstream:
176 description:
177 - Stream option anomalies.
178 type: str
179 choices:
180 - 'allow'
181 - 'drop'
182 - 'trap-to-host'
183 ipv4_opttimestamp:
184 description:
185 - Timestamp option anomalies.
186 type: str
187 choices:
188 - 'allow'
189 - 'drop'
190 - 'trap-to-host'
191 ipv4_proto_err:
192 description:
193 - Invalid layer 4 protocol anomalies.
194 type: str
195 choices:
196 - 'allow'
197 - 'drop'
198 - 'trap-to-host'
199 ipv4_unknopt:
200 description:
201 - Unknown option anomalies.
202 type: str
203 choices:
204 - 'allow'
205 - 'drop'
206 - 'trap-to-host'
207 ipv6_daddr_err:
208 description:
209 - Destination address as unspecified or loopback address anomalies.
210 type: str
211 choices:
212 - 'allow'
213 - 'drop'
214 - 'trap-to-host'
215 ipv6_land:
216 description:
217 - Land anomalies.
218 type: str
219 choices:
220 - 'allow'
221 - 'drop'
222 - 'trap-to-host'
223 ipv6_optendpid:
224 description:
225 - End point identification anomalies.
226 type: str
227 choices:
228 - 'allow'
229 - 'drop'
230 - 'trap-to-host'
231 ipv6_opthomeaddr:
232 description:
233 - Home address option anomalies.
234 type: str
235 choices:
236 - 'allow'
237 - 'drop'
238 - 'trap-to-host'
239 ipv6_optinvld:
240 description:
241 - Invalid option anomalies.Invalid option anomalies.
242 type: str
243 choices:
244 - 'allow'
245 - 'drop'
246 - 'trap-to-host'
247 ipv6_optjumbo:
248 description:
249 - Jumbo options anomalies.
250 type: str
251 choices:
252 - 'allow'
253 - 'drop'
254 - 'trap-to-host'
255 ipv6_optnsap:
256 description:
257 - Network service access point address option anomalies.
258 type: str
259 choices:
260 - 'allow'
261 - 'drop'
262 - 'trap-to-host'
263 ipv6_optralert:
264 description:
265 - Router alert option anomalies.
266 type: str
267 choices:
268 - 'allow'
269 - 'drop'
270 - 'trap-to-host'
271 ipv6_opttunnel:
272 description:
273 - Tunnel encapsulation limit option anomalies.
274 type: str
275 choices:
276 - 'allow'
277 - 'drop'
278 - 'trap-to-host'
279 ipv6_proto_err:
280 description:
281 - Layer 4 invalid protocol anomalies.
282 type: str
283 choices:
284 - 'allow'
285 - 'drop'
286 - 'trap-to-host'
287 ipv6_saddr_err:
288 description:
289 - Source address as multicast anomalies.
290 type: str
291 choices:
292 - 'allow'
293 - 'drop'
294 - 'trap-to-host'
295 ipv6_unknopt:
296 description:
297 - Unknown option anomalies.
298 type: str
299 choices:
300 - 'allow'
301 - 'drop'
302 - 'trap-to-host'
303 tcp_csum_err:
304 description:
305 - Invalid IPv4 TCP checksum anomalies.
306 type: str
307 choices:
308 - 'drop'
309 - 'trap-to-host'
310 tcp_fin_noack:
311 description:
312 - TCP SYN flood with FIN flag set without ACK setting anomalies.
313 type: str
314 choices:
315 - 'allow'
316 - 'drop'
317 - 'trap-to-host'
318 tcp_fin_only:
319 description:
320 - TCP SYN flood with only FIN flag set anomalies.
321 type: str
322 choices:
323 - 'allow'
324 - 'drop'
325 - 'trap-to-host'
326 tcp_land:
327 description:
328 - TCP land anomalies.
329 type: str
330 choices:
331 - 'allow'
332 - 'drop'
333 - 'trap-to-host'
334 tcp_no_flag:
335 description:
336 - TCP SYN flood with no flag set anomalies.
337 type: str
338 choices:
339 - 'allow'
340 - 'drop'
341 - 'trap-to-host'
342 tcp_syn_data:
343 description:
344 - TCP SYN flood packets with data anomalies.
345 type: str
346 choices:
347 - 'allow'
348 - 'drop'
349 - 'trap-to-host'
350 tcp_syn_fin:
351 description:
352 - TCP SYN flood SYN/FIN flag set anomalies.
353 type: str
354 choices:
355 - 'allow'
356 - 'drop'
357 - 'trap-to-host'
358 tcp_winnuke:
359 description:
360 - TCP WinNuke anomalies.
361 type: str
362 choices:
363 - 'allow'
364 - 'drop'
365 - 'trap-to-host'
366 udp_csum_err:
367 description:
368 - Invalid IPv4 UDP checksum anomalies.
369 type: str
370 choices:
371 - 'drop'
372 - 'trap-to-host'
373 udp_land:
374 description:
375 - UDP land anomalies.
376 type: str
377 choices:
378 - 'allow'
379 - 'drop'
380 - 'trap-to-host'
381 garbage_session_collector:
382 description:
383 - Enable/disable garbage session collector.
384 type: str
385 choices:
386 - 'disable'
387 - 'enable'
388 hpe:
389 description:
390 - HPE configuration.
391 type: dict
392 suboptions:
393 arp_max:
394 description:
395 - Maximum ARP packet rate (1K - 1G pps).
396 type: int
397 enable_shaper:
398 description:
399 - Enable/Disable NPU Host Protection Engine(HPE) for packet type shaper.
400 type: str
401 choices:
402 - 'disable'
403 - 'enable'
404 esp_max:
405 description:
406 - Maximum ESP packet rate (1K - 1G pps).
407 type: int
408 icmp_max:
409 description:
410 - Maximum ICMP packet rate (1K - 1G pps).
411 type: int
412 ip_frag_max:
413 description:
414 - Maximum fragmented IP packet rate (1K - 1G pps).
415 type: int
416 ip_others_max:
417 description:
418 - Maximum IP packet rate for other packets (packet types that cannot be set with other options) (1K - 1G pps).
419 type: int
420 l2_others_max:
421 description:
422 - Maximum L2 packet rate for L2 packets that are not ARP packets (1K - 1G pps).
423 type: int
424 pri_type_max:
425 description:
426 - 'Maximum overflow rate of priority type traffic (1K - 1G pps). Includes L2: HA, 802.3ad LACP, heartbeats. L3: OSPF. L4_TCP: BGP.
427 L4_UDP: IKE, SLBC, BFD.'
428 type: int
429 sctp_max:
430 description:
431 - Maximum SCTP packet rate (1K - 1G pps).
432 type: int
433 tcp_max:
434 description:
435 - Maximum TCP packet rate (1K - 1G pps).
436 type: int
437 tcpfin_rst_max:
438 description:
439 - Maximum TCP carries FIN or RST flags packet rate (1K - 1G pps).
440 type: int
441 tcpsyn_ack_max:
442 description:
443 - Maximum TCP carries SYN and ACK flags packet rate (1K - 1G pps).
444 type: int
445 tcpsyn_max:
446 description:
447 - Maximum TCP SYN packet rate (1K - 1G pps).
448 type: int
449 udp_max:
450 description:
451 - Maximum UDP packet rate (1K - 1G pps).
452 type: int
453 ipsec_ob_hash_function:
454 description:
455 - Set hash function for IPSec outbound.
456 type: str
457 choices:
458 - 'global-hash'
459 - 'round-robin-global'
460 ipsec_outbound_hash:
461 description:
462 - Enable/disable hash function for IPsec outbound traffic.
463 type: str
464 choices:
465 - 'disable'
466 - 'enable'
467 low_latency_mode:
468 description:
469 - Enable/disable low latency mode.
470 type: str
471 choices:
472 - 'disable'
473 - 'enable'
474 name:
475 description:
476 - Device Name.
477 required: true
478 type: str
479 per_session_accounting:
480 description:
481 - Enable/disable per-session accounting.
482 type: str
483 choices:
484 - 'disable'
485 - 'traffic-log-only'
486 - 'enable'
487 session_collector_interval:
488 description:
489 - Set garbage session collection cleanup interval (1 - 100 sec).
490 type: int
491 session_timeout_fixed:
492 description:
493 - '{disable | enable} Toggle between using fixed or random timeouts for refreshing NP6 sessions.'
494 type: str
495 choices:
496 - 'disable'
497 - 'enable'
498 session_timeout_interval:
499 description:
500 - Set the fixed timeout for refreshing NP6 sessions (0 - 1000 sec).
501 type: int
502 session_timeout_random_range:
503 description:
504 - Set the random timeout range for refreshing NP6 sessions (0 - 1000 sec).
505 type: int
506 """
507
508 EXAMPLES = """
509 - name: Configure NP6 attributes.
510 fortinet.fortios.fortios_system_np6:
511 vdom: "{{ vdom }}"
512 state: "present"
513 access_token: "<your_own_value>"
514 system_np6:
515 fastpath: "disable"
516 fp_anomaly:
517 icmp_csum_err: "drop"
518 icmp_frag: "allow"
519 icmp_land: "allow"
520 ipv4_csum_err: "drop"
521 ipv4_land: "allow"
522 ipv4_optlsrr: "allow"
523 ipv4_optrr: "allow"
524 ipv4_optsecurity: "allow"
525 ipv4_optssrr: "allow"
526 ipv4_optstream: "allow"
527 ipv4_opttimestamp: "allow"
528 ipv4_proto_err: "allow"
529 ipv4_unknopt: "allow"
530 ipv6_daddr_err: "allow"
531 ipv6_land: "allow"
532 ipv6_optendpid: "allow"
533 ipv6_opthomeaddr: "allow"
534 ipv6_optinvld: "allow"
535 ipv6_optjumbo: "allow"
536 ipv6_optnsap: "allow"
537 ipv6_optralert: "allow"
538 ipv6_opttunnel: "allow"
539 ipv6_proto_err: "allow"
540 ipv6_saddr_err: "allow"
541 ipv6_unknopt: "allow"
542 tcp_csum_err: "drop"
543 tcp_fin_noack: "allow"
544 tcp_fin_only: "allow"
545 tcp_land: "allow"
546 tcp_no_flag: "allow"
547 tcp_syn_data: "allow"
548 tcp_syn_fin: "allow"
549 tcp_winnuke: "allow"
550 udp_csum_err: "drop"
551 udp_land: "allow"
552 garbage_session_collector: "disable"
553 hpe:
554 arp_max: "200000"
555 enable_shaper: "disable"
556 esp_max: "200000"
557 icmp_max: "200000"
558 ip_frag_max: "200000"
559 ip_others_max: "200000"
560 l2_others_max: "200000"
561 pri_type_max: "200000"
562 sctp_max: "200000"
563 tcp_max: "600000"
564 tcpfin_rst_max: "600000"
565 tcpsyn_ack_max: "600000"
566 tcpsyn_max: "600000"
567 udp_max: "600000"
568 ipsec_ob_hash_function: "global-hash"
569 ipsec_outbound_hash: "disable"
570 low_latency_mode: "disable"
571 name: "default_name_59"
572 per_session_accounting: "disable"
573 session_collector_interval: "64"
574 session_timeout_fixed: "disable"
575 session_timeout_interval: "40"
576 session_timeout_random_range: "8"
577 """
578
579 RETURN = """
580 build:
581 description: Build number of the fortigate image
582 returned: always
583 type: str
584 sample: '1547'
585 http_method:
586 description: Last method used to provision the content into FortiGate
587 returned: always
588 type: str
589 sample: 'PUT'
590 http_status:
591 description: Last result given by FortiGate on last operation applied
592 returned: always
593 type: str
594 sample: "200"
595 mkey:
596 description: Master key (id) used in the last call to FortiGate
597 returned: success
598 type: str
599 sample: "id"
600 name:
601 description: Name of the table used to fulfill the request
602 returned: always
603 type: str
604 sample: "urlfilter"
605 path:
606 description: Path of the table used to fulfill the request
607 returned: always
608 type: str
609 sample: "webfilter"
610 revision:
611 description: Internal revision number
612 returned: always
613 type: str
614 sample: "17.0.2.10658"
615 serial:
616 description: Serial number of the unit
617 returned: always
618 type: str
619 sample: "FGVMEVYYQT3AB5352"
620 status:
621 description: Indication of the operation's result
622 returned: always
623 type: str
624 sample: "success"
625 vdom:
626 description: Virtual domain used
627 returned: always
628 type: str
629 sample: "root"
630 version:
631 description: Version of the FortiGate
632 returned: always
633 type: str
634 sample: "v5.6.3"
635 """
636 from ansible.module_utils.basic import AnsibleModule
637 from ansible.module_utils.connection import Connection
638 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
639 FortiOSHandler,
640 )
641 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
642 check_legacy_fortiosapi,
643 )
644 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
645 schema_to_module_spec,
646 )
647 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
648 check_schema_versioning,
649 )
650 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
651 FAIL_SOCKET_MSG,
652 )
653 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
654 remove_invalid_fields,
655 )
656 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
657 is_same_comparison,
658 )
659 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
660 serialize,
661 )
662 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
663 find_current_values,
664 )
665 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
666 unify_data_format,
667 )
668
669
670 def filter_system_np6_data(json):
671 option_list = [
672 "fastpath",
673 "fp_anomaly",
674 "garbage_session_collector",
675 "hpe",
676 "ipsec_ob_hash_function",
677 "ipsec_outbound_hash",
678 "low_latency_mode",
679 "name",
680 "per_session_accounting",
681 "session_collector_interval",
682 "session_timeout_fixed",
683 "session_timeout_interval",
684 "session_timeout_random_range",
685 ]
686
687 json = remove_invalid_fields(json)
688 dictionary = {}
689
690 for attribute in option_list:
691 if attribute in json and json[attribute] is not None:
692 dictionary[attribute] = json[attribute]
693
694 return dictionary
695
696
697 def underscore_to_hyphen(data):
698 new_data = None
699 if isinstance(data, list):
700 new_data = []
701 for i, elem in enumerate(data):
702 new_data.append(underscore_to_hyphen(elem))
703 elif isinstance(data, dict):
704 new_data = {}
705 for k, v in data.items():
706 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
707 else:
708 return data
709 return new_data
710
711
712 def system_np6(data, fos, check_mode=False):
713
714 state = None
715 vdom = data["vdom"]
716 parameters = None
717 state = data.get("state", None)
718 system_np6_data = data["system_np6"]
719
720 filtered_data = filter_system_np6_data(system_np6_data)
721 converted_data = underscore_to_hyphen(filtered_data)
722
723 # check_mode starts from here
724 if check_mode:
725 diff = {
726 "before": "",
727 "after": filtered_data,
728 }
729 mkeyname = fos.get_mkeyname(None, None)
730 mkey = fos.get_mkey("system", "np6", filtered_data, vdom=vdom)
731 current_data = fos.get(
732 "system", "np6", vdom=vdom, mkey=mkey, parameters=parameters
733 )
734 is_existed = (
735 current_data
736 and current_data.get("http_status") == 200
737 and (
738 mkeyname
739 and isinstance(current_data.get("results"), list)
740 and len(current_data["results"]) > 0
741 or not mkeyname
742 and current_data["results"] # global object response
743 )
744 )
745
746 # 2. if it exists and the state is 'present' then compare current settings with desired
747 if state == "present" or state is True or state is None:
748 # for non global modules, mkeyname must exist and it's a new module when mkey is None
749 if mkeyname is not None and mkey is None:
750 return False, True, filtered_data, diff
751
752 # if mkey exists then compare each other
753 # record exits and they're matched or not
754 copied_filtered_data = filtered_data.copy()
755 copied_filtered_data.pop(mkeyname, None)
756 unified_filtered_data = unify_data_format(copied_filtered_data)
757
758 current_data_results = current_data.get("results", {})
759 current_config = (
760 current_data_results[0]
761 if mkeyname
762 and isinstance(current_data_results, list)
763 and len(current_data_results) > 0
764 else current_data_results
765 )
766 if is_existed:
767 unified_current_values = find_current_values(
768 unified_filtered_data,
769 unify_data_format(current_config),
770 )
771
772 is_same = is_same_comparison(
773 serialize(unified_current_values), serialize(unified_filtered_data)
774 )
775
776 return (
777 False,
778 not is_same,
779 filtered_data,
780 {"before": unified_current_values, "after": unified_filtered_data},
781 )
782
783 # record does not exist
784 return False, True, filtered_data, diff
785
786 if state == "absent":
787 if mkey is None:
788 return (
789 False,
790 False,
791 filtered_data,
792 {"before": current_data["results"][0], "after": ""},
793 )
794
795 if is_existed:
796 return (
797 False,
798 True,
799 filtered_data,
800 {"before": current_data["results"][0], "after": ""},
801 )
802 return False, False, filtered_data, {}
803
804 return True, False, {"reason: ": "Must provide state parameter"}, {}
805 # pass post processed data to member operations
806 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
807 data_copy = data.copy()
808 data_copy["system_np6"] = filtered_data
809 fos.do_member_operation(
810 "system",
811 "np6",
812 data_copy,
813 )
814
815 if state == "present" or state is True:
816 return fos.set(
817 "system", "np6", data=converted_data, vdom=vdom, parameters=parameters
818 )
819
820 elif state == "absent":
821 return fos.delete(
822 "system",
823 "np6",
824 mkey=converted_data["name"],
825 vdom=vdom,
826 parameters=parameters,
827 )
828 else:
829 fos._module.fail_json(msg="state must be present or absent!")
830
831
832 def is_successful_status(resp):
833 return (
834 "status" in resp
835 and resp["status"] == "success"
836 or "http_status" in resp
837 and resp["http_status"] == 200
838 or "http_method" in resp
839 and resp["http_method"] == "DELETE"
840 and resp["http_status"] == 404
841 )
842
843
844 def fortios_system(data, fos, check_mode):
845
846 if data["system_np6"]:
847 resp = system_np6(data, fos, check_mode)
848 else:
849 fos._module.fail_json(msg="missing task body: %s" % ("system_np6"))
850 if isinstance(resp, tuple) and len(resp) == 4:
851 return resp
852 return (
853 not is_successful_status(resp),
854 is_successful_status(resp)
855 and (resp["revision_changed"] if "revision_changed" in resp else True),
856 resp,
857 {},
858 )
859
860
861 versioned_schema = {
862 "type": "list",
863 "elements": "dict",
864 "children": {
865 "name": {
866 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
867 "type": "string",
868 "required": True,
869 },
870 "fastpath": {
871 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
872 "type": "string",
873 "options": [{"value": "disable"}, {"value": "enable"}],
874 },
875 "low_latency_mode": {
876 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
877 "type": "string",
878 "options": [{"value": "disable"}, {"value": "enable"}],
879 },
880 "per_session_accounting": {
881 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
882 "type": "string",
883 "options": [
884 {"value": "disable"},
885 {"value": "traffic-log-only"},
886 {"value": "enable"},
887 ],
888 },
889 "garbage_session_collector": {
890 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
891 "type": "string",
892 "options": [{"value": "disable"}, {"value": "enable"}],
893 },
894 "session_collector_interval": {
895 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
896 "type": "integer",
897 },
898 "session_timeout_interval": {
899 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
900 "type": "integer",
901 },
902 "session_timeout_random_range": {
903 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
904 "type": "integer",
905 },
906 "session_timeout_fixed": {
907 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
908 "type": "string",
909 "options": [{"value": "disable"}, {"value": "enable"}],
910 },
911 "hpe": {
912 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
913 "type": "dict",
914 "children": {
915 "tcpsyn_max": {
916 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
917 "type": "integer",
918 },
919 "tcpsyn_ack_max": {
920 "v_range": [["v7.0.0", "v7.4.1"], ["v7.4.3", ""]],
921 "type": "integer",
922 },
923 "tcpfin_rst_max": {
924 "v_range": [["v7.0.0", "v7.4.1"], ["v7.4.3", ""]],
925 "type": "integer",
926 },
927 "tcp_max": {
928 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
929 "type": "integer",
930 },
931 "udp_max": {
932 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
933 "type": "integer",
934 },
935 "icmp_max": {
936 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
937 "type": "integer",
938 },
939 "sctp_max": {
940 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
941 "type": "integer",
942 },
943 "esp_max": {
944 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
945 "type": "integer",
946 },
947 "ip_frag_max": {
948 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
949 "type": "integer",
950 },
951 "ip_others_max": {
952 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
953 "type": "integer",
954 },
955 "arp_max": {
956 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
957 "type": "integer",
958 },
959 "l2_others_max": {
960 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
961 "type": "integer",
962 },
963 "pri_type_max": {
964 "v_range": [
965 ["v6.0.0", "v6.0.0"],
966 ["v6.0.11", "v7.4.1"],
967 ["v7.4.3", ""],
968 ],
969 "type": "integer",
970 },
971 "enable_shaper": {
972 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
973 "type": "string",
974 "options": [{"value": "disable"}, {"value": "enable"}],
975 },
976 },
977 },
978 "fp_anomaly": {
979 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
980 "type": "dict",
981 "children": {
982 "tcp_syn_fin": {
983 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
984 "type": "string",
985 "options": [
986 {"value": "allow"},
987 {"value": "drop"},
988 {"value": "trap-to-host"},
989 ],
990 },
991 "tcp_fin_noack": {
992 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
993 "type": "string",
994 "options": [
995 {"value": "allow"},
996 {"value": "drop"},
997 {"value": "trap-to-host"},
998 ],
999 },
1000 "tcp_fin_only": {
1001 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1002 "type": "string",
1003 "options": [
1004 {"value": "allow"},
1005 {"value": "drop"},
1006 {"value": "trap-to-host"},
1007 ],
1008 },
1009 "tcp_no_flag": {
1010 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1011 "type": "string",
1012 "options": [
1013 {"value": "allow"},
1014 {"value": "drop"},
1015 {"value": "trap-to-host"},
1016 ],
1017 },
1018 "tcp_syn_data": {
1019 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1020 "type": "string",
1021 "options": [
1022 {"value": "allow"},
1023 {"value": "drop"},
1024 {"value": "trap-to-host"},
1025 ],
1026 },
1027 "tcp_winnuke": {
1028 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1029 "type": "string",
1030 "options": [
1031 {"value": "allow"},
1032 {"value": "drop"},
1033 {"value": "trap-to-host"},
1034 ],
1035 },
1036 "tcp_land": {
1037 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1038 "type": "string",
1039 "options": [
1040 {"value": "allow"},
1041 {"value": "drop"},
1042 {"value": "trap-to-host"},
1043 ],
1044 },
1045 "udp_land": {
1046 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1047 "type": "string",
1048 "options": [
1049 {"value": "allow"},
1050 {"value": "drop"},
1051 {"value": "trap-to-host"},
1052 ],
1053 },
1054 "icmp_land": {
1055 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1056 "type": "string",
1057 "options": [
1058 {"value": "allow"},
1059 {"value": "drop"},
1060 {"value": "trap-to-host"},
1061 ],
1062 },
1063 "icmp_frag": {
1064 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1065 "type": "string",
1066 "options": [
1067 {"value": "allow"},
1068 {"value": "drop"},
1069 {"value": "trap-to-host"},
1070 ],
1071 },
1072 "ipv4_land": {
1073 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1074 "type": "string",
1075 "options": [
1076 {"value": "allow"},
1077 {"value": "drop"},
1078 {"value": "trap-to-host"},
1079 ],
1080 },
1081 "ipv4_proto_err": {
1082 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1083 "type": "string",
1084 "options": [
1085 {"value": "allow"},
1086 {"value": "drop"},
1087 {"value": "trap-to-host"},
1088 ],
1089 },
1090 "ipv4_unknopt": {
1091 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1092 "type": "string",
1093 "options": [
1094 {"value": "allow"},
1095 {"value": "drop"},
1096 {"value": "trap-to-host"},
1097 ],
1098 },
1099 "ipv4_optrr": {
1100 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1101 "type": "string",
1102 "options": [
1103 {"value": "allow"},
1104 {"value": "drop"},
1105 {"value": "trap-to-host"},
1106 ],
1107 },
1108 "ipv4_optssrr": {
1109 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1110 "type": "string",
1111 "options": [
1112 {"value": "allow"},
1113 {"value": "drop"},
1114 {"value": "trap-to-host"},
1115 ],
1116 },
1117 "ipv4_optlsrr": {
1118 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1119 "type": "string",
1120 "options": [
1121 {"value": "allow"},
1122 {"value": "drop"},
1123 {"value": "trap-to-host"},
1124 ],
1125 },
1126 "ipv4_optstream": {
1127 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1128 "type": "string",
1129 "options": [
1130 {"value": "allow"},
1131 {"value": "drop"},
1132 {"value": "trap-to-host"},
1133 ],
1134 },
1135 "ipv4_optsecurity": {
1136 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1137 "type": "string",
1138 "options": [
1139 {"value": "allow"},
1140 {"value": "drop"},
1141 {"value": "trap-to-host"},
1142 ],
1143 },
1144 "ipv4_opttimestamp": {
1145 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1146 "type": "string",
1147 "options": [
1148 {"value": "allow"},
1149 {"value": "drop"},
1150 {"value": "trap-to-host"},
1151 ],
1152 },
1153 "ipv4_csum_err": {
1154 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1155 "type": "string",
1156 "options": [{"value": "drop"}, {"value": "trap-to-host"}],
1157 },
1158 "tcp_csum_err": {
1159 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1160 "type": "string",
1161 "options": [{"value": "drop"}, {"value": "trap-to-host"}],
1162 },
1163 "udp_csum_err": {
1164 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1165 "type": "string",
1166 "options": [{"value": "drop"}, {"value": "trap-to-host"}],
1167 },
1168 "icmp_csum_err": {
1169 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1170 "type": "string",
1171 "options": [{"value": "drop"}, {"value": "trap-to-host"}],
1172 },
1173 "ipv6_land": {
1174 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1175 "type": "string",
1176 "options": [
1177 {"value": "allow"},
1178 {"value": "drop"},
1179 {"value": "trap-to-host"},
1180 ],
1181 },
1182 "ipv6_proto_err": {
1183 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1184 "type": "string",
1185 "options": [
1186 {"value": "allow"},
1187 {"value": "drop"},
1188 {"value": "trap-to-host"},
1189 ],
1190 },
1191 "ipv6_unknopt": {
1192 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1193 "type": "string",
1194 "options": [
1195 {"value": "allow"},
1196 {"value": "drop"},
1197 {"value": "trap-to-host"},
1198 ],
1199 },
1200 "ipv6_saddr_err": {
1201 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1202 "type": "string",
1203 "options": [
1204 {"value": "allow"},
1205 {"value": "drop"},
1206 {"value": "trap-to-host"},
1207 ],
1208 },
1209 "ipv6_daddr_err": {
1210 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1211 "type": "string",
1212 "options": [
1213 {"value": "allow"},
1214 {"value": "drop"},
1215 {"value": "trap-to-host"},
1216 ],
1217 },
1218 "ipv6_optralert": {
1219 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1220 "type": "string",
1221 "options": [
1222 {"value": "allow"},
1223 {"value": "drop"},
1224 {"value": "trap-to-host"},
1225 ],
1226 },
1227 "ipv6_optjumbo": {
1228 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1229 "type": "string",
1230 "options": [
1231 {"value": "allow"},
1232 {"value": "drop"},
1233 {"value": "trap-to-host"},
1234 ],
1235 },
1236 "ipv6_opttunnel": {
1237 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1238 "type": "string",
1239 "options": [
1240 {"value": "allow"},
1241 {"value": "drop"},
1242 {"value": "trap-to-host"},
1243 ],
1244 },
1245 "ipv6_opthomeaddr": {
1246 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1247 "type": "string",
1248 "options": [
1249 {"value": "allow"},
1250 {"value": "drop"},
1251 {"value": "trap-to-host"},
1252 ],
1253 },
1254 "ipv6_optnsap": {
1255 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1256 "type": "string",
1257 "options": [
1258 {"value": "allow"},
1259 {"value": "drop"},
1260 {"value": "trap-to-host"},
1261 ],
1262 },
1263 "ipv6_optendpid": {
1264 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1265 "type": "string",
1266 "options": [
1267 {"value": "allow"},
1268 {"value": "drop"},
1269 {"value": "trap-to-host"},
1270 ],
1271 },
1272 "ipv6_optinvld": {
1273 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1274 "type": "string",
1275 "options": [
1276 {"value": "allow"},
1277 {"value": "drop"},
1278 {"value": "trap-to-host"},
1279 ],
1280 },
1281 },
1282 },
1283 "ipsec_outbound_hash": {
1284 "v_range": [
1285 ["v6.0.0", "v6.2.7"],
1286 ["v6.4.1", "v7.0.12"],
1287 ["v7.2.1", "v7.2.4"],
1288 ],
1289 "type": "string",
1290 "options": [{"value": "disable"}, {"value": "enable"}],
1291 },
1292 "ipsec_ob_hash_function": {
1293 "v_range": [
1294 ["v6.0.0", "v6.2.7"],
1295 ["v6.4.1", "v7.0.12"],
1296 ["v7.2.1", "v7.2.4"],
1297 ],
1298 "type": "string",
1299 "options": [{"value": "global-hash"}, {"value": "round-robin-global"}],
1300 },
1301 },
1302 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
1303 }
1304
1305
1306 def main():
1307 module_spec = schema_to_module_spec(versioned_schema)
1308 mkeyname = "name"
1309 fields = {
1310 "access_token": {"required": False, "type": "str", "no_log": True},
1311 "enable_log": {"required": False, "type": "bool", "default": False},
1312 "vdom": {"required": False, "type": "str", "default": "root"},
1313 "member_path": {"required": False, "type": "str"},
1314 "member_state": {
1315 "type": "str",
1316 "required": False,
1317 "choices": ["present", "absent"],
1318 },
1319 "state": {"required": True, "type": "str", "choices": ["present", "absent"]},
1320 "system_np6": {
1321 "required": False,
1322 "type": "dict",
1323 "default": None,
1324 "options": {},
1325 },
1326 }
1327 for attribute_name in module_spec["options"]:
1328 fields["system_np6"]["options"][attribute_name] = module_spec["options"][
1329 attribute_name
1330 ]
1331 if mkeyname and mkeyname == attribute_name:
1332 fields["system_np6"]["options"][attribute_name]["required"] = True
1333
1334 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
1335 check_legacy_fortiosapi(module)
1336
1337 is_error = False
1338 has_changed = False
1339 result = None
1340 diff = None
1341
1342 versions_check_result = None
1343 if module._socket_path:
1344 connection = Connection(module._socket_path)
1345 if "access_token" in module.params:
1346 connection.set_custom_option("access_token", module.params["access_token"])
1347
1348 if "enable_log" in module.params:
1349 connection.set_custom_option("enable_log", module.params["enable_log"])
1350 else:
1351 connection.set_custom_option("enable_log", False)
1352 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
1353 versions_check_result = check_schema_versioning(
1354 fos, versioned_schema, "system_np6"
1355 )
1356
1357 is_error, has_changed, result, diff = fortios_system(
1358 module.params, fos, module.check_mode
1359 )
1360
1361 else:
1362 module.fail_json(**FAIL_SOCKET_MSG)
1363
1364 if versions_check_result and versions_check_result["matched"] is False:
1365 module.warn(
1366 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
1367 )
1368
1369 if not is_error:
1370 if versions_check_result and versions_check_result["matched"] is False:
1371 module.exit_json(
1372 changed=has_changed,
1373 version_check_warning=versions_check_result,
1374 meta=result,
1375 diff=diff,
1376 )
1377 else:
1378 module.exit_json(changed=has_changed, meta=result, diff=diff)
1379 else:
1380 if versions_check_result and versions_check_result["matched"] is False:
1381 module.fail_json(
1382 msg="Error in repo",
1383 version_check_warning=versions_check_result,
1384 meta=result,
1385 )
1386 else:
1387 module.fail_json(msg="Error in repo", meta=result)
1388
1389
1390 if __name__ == "__main__":
1391 main()