Debian Codegraph @

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