Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_certificate_local.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_certificate_local
23 short_description: Local keys and certificates 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 certificate feature and local 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 certificate_local:
88 description:
89 - Local keys and certificates.
90 default: null
91 type: dict
92 suboptions:
93 acme_ca_url:
94 description:
95 - The URL for the ACME CA server (Let"s Encrypt is the ).
96 type: str
97 acme_domain:
98 description:
99 - A valid domain that resolves to this FortiGate unit.
100 type: str
101 acme_eab_key_hmac:
102 description:
103 - External Account Binding HMAC Key (URL-encoded base64).
104 type: str
105 acme_eab_key_id:
106 description:
107 - External Account Binding Key ID (optional setting).
108 type: str
109 acme_email:
110 description:
111 - Contact email address that is required by some CAs like LetsEncrypt.
112 type: str
113 acme_renew_window:
114 description:
115 - Beginning of the renewal window (in days before certificate expiration, 30 by default).
116 type: int
117 acme_rsa_key_size:
118 description:
119 - Length of the RSA private key of the generated cert (Minimum 2048 bits).
120 type: int
121 auto_regenerate_days:
122 description:
123 - Number of days to wait before expiry of an updated local certificate is requested (0 = disabled).
124 type: int
125 auto_regenerate_days_warning:
126 description:
127 - Number of days to wait before an expiry warning message is generated (0 = disabled).
128 type: int
129 ca_identifier:
130 description:
131 - CA identifier of the CA server for signing via SCEP.
132 type: str
133 certificate:
134 description:
135 - PEM format certificate.
136 type: str
137 cmp_path:
138 description:
139 - Path location inside CMP server.
140 type: str
141 cmp_regeneration_method:
142 description:
143 - CMP auto-regeneration method.
144 type: str
145 choices:
146 - 'keyupate'
147 - 'renewal'
148 cmp_server:
149 description:
150 - 'Address and port for CMP server (format = address:port).'
151 type: str
152 cmp_server_cert:
153 description:
154 - CMP server certificate. Source certificate.ca.name certificate.remote.name.
155 type: str
156 comments:
157 description:
158 - Comment.
159 type: str
160 csr:
161 description:
162 - Certificate Signing Request.
163 type: str
164 enroll_protocol:
165 description:
166 - Certificate enrollment protocol.
167 type: str
168 choices:
169 - 'none'
170 - 'scep'
171 - 'cmpv2'
172 - 'acme2'
173 - 'est'
174 est_ca_id:
175 description:
176 - CA identifier of the CA server for signing via EST.
177 type: str
178 est_client_cert:
179 description:
180 - Certificate used to authenticate this FortiGate to EST server. Source certificate.local.name.
181 type: str
182 est_http_password:
183 description:
184 - HTTP Authentication password for signing via EST.
185 type: str
186 est_http_username:
187 description:
188 - HTTP Authentication username for signing via EST.
189 type: str
190 est_regeneration_method:
191 description:
192 - EST behavioral options during re-enrollment.
193 type: str
194 choices:
195 - 'create-new-key'
196 - 'use-existing-key'
197 est_server:
198 description:
199 - 'Address and port for EST server (e.g. https://example.com:1234).'
200 type: str
201 est_server_cert:
202 description:
203 - EST server"s certificate must be verifiable by this certificate to be authenticated. Source certificate.ca.name certificate.remote.name.
204 type: str
205 est_srp_password:
206 description:
207 - EST SRP authentication password.
208 type: str
209 est_srp_username:
210 description:
211 - EST SRP authentication username.
212 type: str
213 ike_localid:
214 description:
215 - Local ID the FortiGate uses for authentication as a VPN client.
216 type: str
217 ike_localid_type:
218 description:
219 - IKE local ID type.
220 type: str
221 choices:
222 - 'asn1dn'
223 - 'fqdn'
224 last_updated:
225 description:
226 - Time at which certificate was last updated.
227 type: int
228 name:
229 description:
230 - Name.
231 required: true
232 type: str
233 name_encoding:
234 description:
235 - Name encoding method for auto-regeneration.
236 type: str
237 choices:
238 - 'printable'
239 - 'utf8'
240 password:
241 description:
242 - Password as a PEM file.
243 type: str
244 private_key:
245 description:
246 - PEM format key encrypted with a password.
247 type: str
248 private_key_retain:
249 description:
250 - Enable/disable retention of private key during SCEP renewal .
251 type: str
252 choices:
253 - 'enable'
254 - 'disable'
255 range:
256 description:
257 - Either a global or VDOM IP address range for the certificate.
258 type: str
259 choices:
260 - 'global'
261 - 'vdom'
262 scep_password:
263 description:
264 - SCEP server challenge password for auto-regeneration.
265 type: str
266 scep_url:
267 description:
268 - SCEP server URL.
269 type: str
270 source:
271 description:
272 - Certificate source type.
273 type: str
274 choices:
275 - 'factory'
276 - 'user'
277 - 'bundle'
278 source_ip:
279 description:
280 - Source IP address for communications to the SCEP server.
281 type: str
282 state:
283 description:
284 - Certificate Signing Request State.
285 type: str
286 """
287
288 EXAMPLES = """
289 - name: Local keys and certificates.
290 fortinet.fortios.fortios_certificate_local:
291 vdom: "{{ vdom }}"
292 state: "present"
293 access_token: "<your_own_value>"
294 certificate_local:
295 acme_ca_url: "<your_own_value>"
296 acme_domain: "<your_own_value>"
297 acme_eab_key_hmac: "<your_own_value>"
298 acme_eab_key_id: "<your_own_value>"
299 acme_email: "<your_own_value>"
300 acme_renew_window: "30"
301 acme_rsa_key_size: "2048"
302 auto_regenerate_days: "0"
303 auto_regenerate_days_warning: "0"
304 ca_identifier: "myId_12"
305 certificate: "<your_own_value>"
306 cmp_path: "<your_own_value>"
307 cmp_regeneration_method: "keyupate"
308 cmp_server: "<your_own_value>"
309 cmp_server_cert: "<your_own_value> (source certificate.ca.name certificate.remote.name)"
310 comments: "<your_own_value>"
311 csr: "<your_own_value>"
312 enroll_protocol: "none"
313 est_ca_id: "<your_own_value>"
314 est_client_cert: "<your_own_value> (source certificate.local.name)"
315 est_http_password: "<your_own_value>"
316 est_http_username: "<your_own_value>"
317 est_regeneration_method: "create-new-key"
318 est_server: "<your_own_value>"
319 est_server_cert: "<your_own_value> (source certificate.ca.name certificate.remote.name)"
320 est_srp_password: "<your_own_value>"
321 est_srp_username: "<your_own_value>"
322 ike_localid: "<your_own_value>"
323 ike_localid_type: "asn1dn"
324 last_updated: "2147483647"
325 name: "default_name_33"
326 name_encoding: "printable"
327 password: "<your_own_value>"
328 private_key: "<your_own_value>"
329 private_key_retain: "enable"
330 range: "global"
331 scep_password: "<your_own_value>"
332 scep_url: "<your_own_value>"
333 source: "factory"
334 source_ip: "84.230.14.43"
335 state: "<your_own_value>"
336 """
337
338 RETURN = """
339 build:
340 description: Build number of the fortigate image
341 returned: always
342 type: str
343 sample: '1547'
344 http_method:
345 description: Last method used to provision the content into FortiGate
346 returned: always
347 type: str
348 sample: 'PUT'
349 http_status:
350 description: Last result given by FortiGate on last operation applied
351 returned: always
352 type: str
353 sample: "200"
354 mkey:
355 description: Master key (id) used in the last call to FortiGate
356 returned: success
357 type: str
358 sample: "id"
359 name:
360 description: Name of the table used to fulfill the request
361 returned: always
362 type: str
363 sample: "urlfilter"
364 path:
365 description: Path of the table used to fulfill the request
366 returned: always
367 type: str
368 sample: "webfilter"
369 revision:
370 description: Internal revision number
371 returned: always
372 type: str
373 sample: "17.0.2.10658"
374 serial:
375 description: Serial number of the unit
376 returned: always
377 type: str
378 sample: "FGVMEVYYQT3AB5352"
379 status:
380 description: Indication of the operation's result
381 returned: always
382 type: str
383 sample: "success"
384 vdom:
385 description: Virtual domain used
386 returned: always
387 type: str
388 sample: "root"
389 version:
390 description: Version of the FortiGate
391 returned: always
392 type: str
393 sample: "v5.6.3"
394 """
395 from ansible.module_utils.basic import AnsibleModule
396 from ansible.module_utils.connection import Connection
397 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
398 FortiOSHandler,
399 )
400 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
401 check_legacy_fortiosapi,
402 )
403 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
404 schema_to_module_spec,
405 )
406 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
407 check_schema_versioning,
408 )
409 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
410 FAIL_SOCKET_MSG,
411 )
412 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
413 remove_invalid_fields,
414 )
415 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
416 is_same_comparison,
417 )
418 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
419 serialize,
420 )
421 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
422 find_current_values,
423 )
424 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
425 unify_data_format,
426 )
427
428
429 def filter_certificate_local_data(json):
430 option_list = [
431 "acme_ca_url",
432 "acme_domain",
433 "acme_eab_key_hmac",
434 "acme_eab_key_id",
435 "acme_email",
436 "acme_renew_window",
437 "acme_rsa_key_size",
438 "auto_regenerate_days",
439 "auto_regenerate_days_warning",
440 "ca_identifier",
441 "certificate",
442 "cmp_path",
443 "cmp_regeneration_method",
444 "cmp_server",
445 "cmp_server_cert",
446 "comments",
447 "csr",
448 "enroll_protocol",
449 "est_ca_id",
450 "est_client_cert",
451 "est_http_password",
452 "est_http_username",
453 "est_regeneration_method",
454 "est_server",
455 "est_server_cert",
456 "est_srp_password",
457 "est_srp_username",
458 "ike_localid",
459 "ike_localid_type",
460 "last_updated",
461 "name",
462 "name_encoding",
463 "password",
464 "private_key",
465 "private_key_retain",
466 "range",
467 "scep_password",
468 "scep_url",
469 "source",
470 "source_ip",
471 "state",
472 ]
473
474 json = remove_invalid_fields(json)
475 dictionary = {}
476
477 for attribute in option_list:
478 if attribute in json and json[attribute] is not None:
479 dictionary[attribute] = json[attribute]
480
481 return dictionary
482
483
484 def underscore_to_hyphen(data):
485 new_data = None
486 if isinstance(data, list):
487 new_data = []
488 for i, elem in enumerate(data):
489 new_data.append(underscore_to_hyphen(elem))
490 elif isinstance(data, dict):
491 new_data = {}
492 for k, v in data.items():
493 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
494 else:
495 return data
496 return new_data
497
498
499 def certificate_local(data, fos, check_mode=False):
500
501 state = None
502 vdom = data["vdom"]
503 parameters = None
504 state = data.get("state", None)
505 certificate_local_data = data["certificate_local"]
506
507 filtered_data = filter_certificate_local_data(certificate_local_data)
508 converted_data = underscore_to_hyphen(filtered_data)
509
510 # check_mode starts from here
511 if check_mode:
512 diff = {
513 "before": "",
514 "after": filtered_data,
515 }
516 mkeyname = fos.get_mkeyname(None, None)
517 mkey = fos.get_mkey("certificate", "local", filtered_data, vdom=vdom)
518 current_data = fos.get(
519 "certificate", "local", vdom=vdom, mkey=mkey, parameters=parameters
520 )
521 is_existed = (
522 current_data
523 and current_data.get("http_status") == 200
524 and (
525 mkeyname
526 and isinstance(current_data.get("results"), list)
527 and len(current_data["results"]) > 0
528 or not mkeyname
529 and current_data["results"] # global object response
530 )
531 )
532
533 # 2. if it exists and the state is 'present' then compare current settings with desired
534 if state == "present" or state is True or state is None:
535 # for non global modules, mkeyname must exist and it's a new module when mkey is None
536 if mkeyname is not None and mkey is None:
537 return False, True, filtered_data, diff
538
539 # if mkey exists then compare each other
540 # record exits and they're matched or not
541 copied_filtered_data = filtered_data.copy()
542 copied_filtered_data.pop(mkeyname, None)
543 unified_filtered_data = unify_data_format(copied_filtered_data)
544
545 current_data_results = current_data.get("results", {})
546 current_config = (
547 current_data_results[0]
548 if mkeyname
549 and isinstance(current_data_results, list)
550 and len(current_data_results) > 0
551 else current_data_results
552 )
553 if is_existed:
554 unified_current_values = find_current_values(
555 unified_filtered_data,
556 unify_data_format(current_config),
557 )
558
559 is_same = is_same_comparison(
560 serialize(unified_current_values), serialize(unified_filtered_data)
561 )
562
563 return (
564 False,
565 not is_same,
566 filtered_data,
567 {"before": unified_current_values, "after": unified_filtered_data},
568 )
569
570 # record does not exist
571 return False, True, filtered_data, diff
572
573 if state == "absent":
574 if mkey is None:
575 return (
576 False,
577 False,
578 filtered_data,
579 {"before": current_data["results"][0], "after": ""},
580 )
581
582 if is_existed:
583 return (
584 False,
585 True,
586 filtered_data,
587 {"before": current_data["results"][0], "after": ""},
588 )
589 return False, False, filtered_data, {}
590
591 return True, False, {"reason: ": "Must provide state parameter"}, {}
592 # pass post processed data to member operations
593 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
594 data_copy = data.copy()
595 data_copy["certificate_local"] = filtered_data
596 fos.do_member_operation(
597 "certificate",
598 "local",
599 data_copy,
600 )
601
602 if state == "present" or state is True:
603 return fos.set(
604 "certificate",
605 "local",
606 data=converted_data,
607 vdom=vdom,
608 parameters=parameters,
609 )
610
611 elif state == "absent":
612 return fos.delete(
613 "certificate",
614 "local",
615 mkey=converted_data["name"],
616 vdom=vdom,
617 parameters=parameters,
618 )
619 else:
620 fos._module.fail_json(msg="state must be present or absent!")
621
622
623 def is_successful_status(resp):
624 return (
625 "status" in resp
626 and resp["status"] == "success"
627 or "http_status" in resp
628 and resp["http_status"] == 200
629 or "http_method" in resp
630 and resp["http_method"] == "DELETE"
631 and resp["http_status"] == 404
632 )
633
634
635 def fortios_certificate(data, fos, check_mode):
636
637 if data["certificate_local"]:
638 resp = certificate_local(data, fos, check_mode)
639 else:
640 fos._module.fail_json(msg="missing task body: %s" % ("certificate_local"))
641 if isinstance(resp, tuple) and len(resp) == 4:
642 return resp
643 return (
644 not is_successful_status(resp),
645 is_successful_status(resp)
646 and (resp["revision_changed"] if "revision_changed" in resp else True),
647 resp,
648 {},
649 )
650
651
652 versioned_schema = {
653 "type": "list",
654 "elements": "dict",
655 "children": {
656 "name": {"v_range": [["v6.0.0", ""]], "type": "string", "required": True},
657 "password": {"v_range": [["v6.0.0", ""]], "type": "string"},
658 "comments": {"v_range": [["v6.0.0", ""]], "type": "string"},
659 "private_key": {"v_range": [["v6.0.0", ""]], "type": "string"},
660 "certificate": {"v_range": [["v6.0.0", ""]], "type": "string"},
661 "csr": {"v_range": [["v6.0.0", ""]], "type": "string"},
662 "scep_url": {"v_range": [["v6.0.0", ""]], "type": "string"},
663 "range": {
664 "v_range": [["v6.0.0", ""]],
665 "type": "string",
666 "options": [{"value": "global"}, {"value": "vdom"}],
667 },
668 "source": {
669 "v_range": [["v6.0.0", ""]],
670 "type": "string",
671 "options": [{"value": "factory"}, {"value": "user"}, {"value": "bundle"}],
672 },
673 "auto_regenerate_days": {"v_range": [["v6.0.0", ""]], "type": "integer"},
674 "auto_regenerate_days_warning": {
675 "v_range": [["v6.0.0", ""]],
676 "type": "integer",
677 },
678 "scep_password": {"v_range": [["v6.0.0", ""]], "type": "string"},
679 "ca_identifier": {"v_range": [["v6.0.0", ""]], "type": "string"},
680 "name_encoding": {
681 "v_range": [["v6.0.0", ""]],
682 "type": "string",
683 "options": [{"value": "printable"}, {"value": "utf8"}],
684 },
685 "source_ip": {"v_range": [["v6.0.0", ""]], "type": "string"},
686 "ike_localid": {"v_range": [["v6.0.0", ""]], "type": "string"},
687 "ike_localid_type": {
688 "v_range": [["v6.0.0", ""]],
689 "type": "string",
690 "options": [{"value": "asn1dn"}, {"value": "fqdn"}],
691 },
692 "enroll_protocol": {
693 "v_range": [["v6.0.0", ""]],
694 "type": "string",
695 "options": [
696 {"value": "none"},
697 {"value": "scep"},
698 {"value": "cmpv2"},
699 {"value": "acme2", "v_range": [["v7.0.0", ""]]},
700 {"value": "est", "v_range": [["v7.4.1", ""]]},
701 ],
702 },
703 "private_key_retain": {
704 "v_range": [["v7.2.1", ""]],
705 "type": "string",
706 "options": [{"value": "enable"}, {"value": "disable"}],
707 },
708 "cmp_server": {"v_range": [["v6.0.0", ""]], "type": "string"},
709 "cmp_path": {"v_range": [["v6.0.0", ""]], "type": "string"},
710 "cmp_server_cert": {"v_range": [["v6.0.0", ""]], "type": "string"},
711 "cmp_regeneration_method": {
712 "v_range": [["v6.0.0", ""]],
713 "type": "string",
714 "options": [{"value": "keyupate"}, {"value": "renewal"}],
715 },
716 "acme_ca_url": {"v_range": [["v7.0.0", ""]], "type": "string"},
717 "acme_domain": {"v_range": [["v7.0.0", ""]], "type": "string"},
718 "acme_email": {"v_range": [["v7.0.0", ""]], "type": "string"},
719 "acme_eab_key_id": {"v_range": [["v7.6.3", ""]], "type": "string"},
720 "acme_eab_key_hmac": {"v_range": [["v7.6.3", ""]], "type": "string"},
721 "acme_rsa_key_size": {"v_range": [["v7.0.0", ""]], "type": "integer"},
722 "acme_renew_window": {"v_range": [["v7.0.0", ""]], "type": "integer"},
723 "est_server": {"v_range": [["v7.4.1", ""]], "type": "string"},
724 "est_ca_id": {"v_range": [["v7.4.1", ""]], "type": "string"},
725 "est_http_username": {"v_range": [["v7.4.1", ""]], "type": "string"},
726 "est_http_password": {"v_range": [["v7.4.1", ""]], "type": "string"},
727 "est_client_cert": {"v_range": [["v7.4.1", ""]], "type": "string"},
728 "est_server_cert": {"v_range": [["v7.4.1", ""]], "type": "string"},
729 "est_srp_username": {"v_range": [["v7.4.1", ""]], "type": "string"},
730 "est_srp_password": {"v_range": [["v7.4.1", ""]], "type": "string"},
731 "est_regeneration_method": {
732 "v_range": [["v7.6.3", ""]],
733 "type": "string",
734 "options": [{"value": "create-new-key"}, {"value": "use-existing-key"}],
735 },
736 "state": {
737 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
738 "type": "string",
739 },
740 "last_updated": {
741 "v_range": [["v6.0.0", "v6.0.11"], ["v6.2.3", "v6.2.3"]],
742 "type": "integer",
743 },
744 },
745 "v_range": [["v6.0.0", ""]],
746 }
747
748
749 def main():
750 module_spec = schema_to_module_spec(versioned_schema)
751 mkeyname = "name"
752 fields = {
753 "access_token": {"required": False, "type": "str", "no_log": True},
754 "enable_log": {"required": False, "type": "bool", "default": False},
755 "vdom": {"required": False, "type": "str", "default": "root"},
756 "member_path": {"required": False, "type": "str"},
757 "member_state": {
758 "type": "str",
759 "required": False,
760 "choices": ["present", "absent"],
761 },
762 "state": {"required": True, "type": "str", "choices": ["present", "absent"]},
763 "certificate_local": {
764 "required": False,
765 "type": "dict",
766 "default": None,
767 "options": {},
768 },
769 }
770 for attribute_name in module_spec["options"]:
771 fields["certificate_local"]["options"][attribute_name] = module_spec["options"][
772 attribute_name
773 ]
774 if mkeyname and mkeyname == attribute_name:
775 fields["certificate_local"]["options"][attribute_name]["required"] = True
776
777 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
778 check_legacy_fortiosapi(module)
779
780 is_error = False
781 has_changed = False
782 result = None
783 diff = None
784
785 versions_check_result = None
786 if module._socket_path:
787 connection = Connection(module._socket_path)
788 if "access_token" in module.params:
789 connection.set_custom_option("access_token", module.params["access_token"])
790
791 if "enable_log" in module.params:
792 connection.set_custom_option("enable_log", module.params["enable_log"])
793 else:
794 connection.set_custom_option("enable_log", False)
795 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
796 versions_check_result = check_schema_versioning(
797 fos, versioned_schema, "certificate_local"
798 )
799
800 is_error, has_changed, result, diff = fortios_certificate(
801 module.params, fos, module.check_mode
802 )
803
804 else:
805 module.fail_json(**FAIL_SOCKET_MSG)
806
807 if versions_check_result and versions_check_result["matched"] is False:
808 module.warn(
809 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
810 )
811
812 if not is_error:
813 if versions_check_result and versions_check_result["matched"] is False:
814 module.exit_json(
815 changed=has_changed,
816 version_check_warning=versions_check_result,
817 meta=result,
818 diff=diff,
819 )
820 else:
821 module.exit_json(changed=has_changed, meta=result, diff=diff)
822 else:
823 if versions_check_result and versions_check_result["matched"] is False:
824 module.fail_json(
825 msg="Error in repo",
826 version_check_warning=versions_check_result,
827 meta=result,
828 )
829 else:
830 module.fail_json(msg="Error in repo", meta=result)
831
832
833 if __name__ == "__main__":
834 main()