Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_user_setting.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_user_setting
23 short_description: Configure user authentication setting 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 user feature and setting 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 user_setting:
80 description:
81 - Configure user authentication setting.
82 default: null
83 type: dict
84 suboptions:
85 auth_blackout_time:
86 description:
87 - Time in seconds an IP address is denied access after failing to authenticate five times within one minute.
88 type: int
89 auth_ca_cert:
90 description:
91 - HTTPS CA certificate for policy authentication. Source vpn.certificate.local.name.
92 type: str
93 auth_cert:
94 description:
95 - HTTPS server certificate for policy authentication. Source vpn.certificate.local.name.
96 type: str
97 auth_http_basic:
98 description:
99 - Enable/disable use of HTTP basic authentication for identity-based firewall policies.
100 type: str
101 choices:
102 - 'enable'
103 - 'disable'
104 auth_invalid_max:
105 description:
106 - Maximum number of failed authentication attempts before the user is blocked.
107 type: int
108 auth_lockout_duration:
109 description:
110 - Lockout period in seconds after too many login failures.
111 type: int
112 auth_lockout_threshold:
113 description:
114 - Maximum number of failed login attempts before login lockout is triggered.
115 type: int
116 auth_on_demand:
117 description:
118 - Always/implicitly trigger firewall authentication on demand.
119 type: str
120 choices:
121 - 'always'
122 - 'implicitly'
123 auth_portal_timeout:
124 description:
125 - Time in minutes before captive portal user have to re-authenticate (1 - 30 min).
126 type: int
127 auth_ports:
128 description:
129 - Set up non-standard ports for authentication with HTTP, HTTPS, FTP, and TELNET.
130 type: list
131 elements: dict
132 suboptions:
133 id:
134 description:
135 - ID. see <a href='#notes'>Notes</a>.
136 required: true
137 type: int
138 port:
139 description:
140 - Non-standard port for firewall user authentication.
141 type: int
142 type:
143 description:
144 - Service type.
145 type: str
146 choices:
147 - 'http'
148 - 'https'
149 - 'ftp'
150 - 'telnet'
151 auth_secure_http:
152 description:
153 - Enable/disable redirecting HTTP user authentication to more secure HTTPS.
154 type: str
155 choices:
156 - 'enable'
157 - 'disable'
158 auth_src_mac:
159 description:
160 - Enable/disable source MAC for user identity.
161 type: str
162 choices:
163 - 'enable'
164 - 'disable'
165 auth_ssl_allow_renegotiation:
166 description:
167 - Allow/forbid SSL re-negotiation for HTTPS authentication.
168 type: str
169 choices:
170 - 'enable'
171 - 'disable'
172 auth_ssl_max_proto_version:
173 description:
174 - Maximum supported protocol version for SSL/TLS connections .
175 type: str
176 choices:
177 - 'sslv3'
178 - 'tlsv1'
179 - 'tlsv1-1'
180 - 'tlsv1-2'
181 - 'tlsv1-3'
182 auth_ssl_min_proto_version:
183 description:
184 - Minimum supported protocol version for SSL/TLS connections .
185 type: str
186 choices:
187 - 'default'
188 - 'SSLv3'
189 - 'TLSv1'
190 - 'TLSv1-1'
191 - 'TLSv1-2'
192 - 'TLSv1-3'
193 auth_ssl_sigalgs:
194 description:
195 - Set signature algorithms related to HTTPS authentication (affects TLS version <= 1.2 only).
196 type: str
197 choices:
198 - 'no-rsa-pss'
199 - 'all'
200 auth_timeout:
201 description:
202 - Time in minutes before the firewall user authentication timeout requires the user to re-authenticate.
203 type: int
204 auth_timeout_type:
205 description:
206 - Control if authenticated users have to login again after a hard timeout, after an idle timeout, or after a session timeout.
207 type: str
208 choices:
209 - 'idle-timeout'
210 - 'hard-timeout'
211 - 'new-session'
212 auth_type:
213 description:
214 - Supported firewall policy authentication protocols/methods.
215 type: list
216 elements: str
217 choices:
218 - 'http'
219 - 'https'
220 - 'ftp'
221 - 'telnet'
222 cors:
223 description:
224 - Enable/disable allowed origins white list for CORS.
225 type: str
226 choices:
227 - 'disable'
228 - 'enable'
229 cors_allowed_origins:
230 description:
231 - Allowed origins white list for CORS.
232 type: list
233 elements: dict
234 suboptions:
235 name:
236 description:
237 - Allowed origin for CORS.
238 required: true
239 type: str
240 default_user_password_policy:
241 description:
242 - Default password policy to apply to all local users unless otherwise specified, as defined in config user password-policy. Source user
243 .password-policy.name.
244 type: str
245 per_policy_disclaimer:
246 description:
247 - Enable/disable per policy disclaimer.
248 type: str
249 choices:
250 - 'enable'
251 - 'disable'
252 radius_ses_timeout_act:
253 description:
254 - Set the RADIUS session timeout to a hard timeout or to ignore RADIUS server session timeouts.
255 type: str
256 choices:
257 - 'hard-timeout'
258 - 'ignore-timeout'
259 """
260
261 EXAMPLES = """
262 - name: Configure user authentication setting.
263 fortinet.fortios.fortios_user_setting:
264 vdom: "{{ vdom }}"
265 user_setting:
266 auth_blackout_time: "0"
267 auth_ca_cert: "<your_own_value> (source vpn.certificate.local.name)"
268 auth_cert: "<your_own_value> (source vpn.certificate.local.name)"
269 auth_http_basic: "enable"
270 auth_invalid_max: "5"
271 auth_lockout_duration: "0"
272 auth_lockout_threshold: "3"
273 auth_on_demand: "always"
274 auth_portal_timeout: "3"
275 auth_ports:
276 -
277 id: "13"
278 port: "1024"
279 type: "http"
280 auth_secure_http: "enable"
281 auth_src_mac: "enable"
282 auth_ssl_allow_renegotiation: "enable"
283 auth_ssl_max_proto_version: "sslv3"
284 auth_ssl_min_proto_version: "default"
285 auth_ssl_sigalgs: "no-rsa-pss"
286 auth_timeout: "5"
287 auth_timeout_type: "idle-timeout"
288 auth_type: "http"
289 cors: "disable"
290 cors_allowed_origins:
291 -
292 name: "default_name_27"
293 default_user_password_policy: "<your_own_value> (source user.password-policy.name)"
294 per_policy_disclaimer: "enable"
295 radius_ses_timeout_act: "hard-timeout"
296 """
297
298 RETURN = """
299 build:
300 description: Build number of the fortigate image
301 returned: always
302 type: str
303 sample: '1547'
304 http_method:
305 description: Last method used to provision the content into FortiGate
306 returned: always
307 type: str
308 sample: 'PUT'
309 http_status:
310 description: Last result given by FortiGate on last operation applied
311 returned: always
312 type: str
313 sample: "200"
314 mkey:
315 description: Master key (id) used in the last call to FortiGate
316 returned: success
317 type: str
318 sample: "id"
319 name:
320 description: Name of the table used to fulfill the request
321 returned: always
322 type: str
323 sample: "urlfilter"
324 path:
325 description: Path of the table used to fulfill the request
326 returned: always
327 type: str
328 sample: "webfilter"
329 revision:
330 description: Internal revision number
331 returned: always
332 type: str
333 sample: "17.0.2.10658"
334 serial:
335 description: Serial number of the unit
336 returned: always
337 type: str
338 sample: "FGVMEVYYQT3AB5352"
339 status:
340 description: Indication of the operation's result
341 returned: always
342 type: str
343 sample: "success"
344 vdom:
345 description: Virtual domain used
346 returned: always
347 type: str
348 sample: "root"
349 version:
350 description: Version of the FortiGate
351 returned: always
352 type: str
353 sample: "v5.6.3"
354 """
355 from ansible.module_utils.basic import AnsibleModule
356 from ansible.module_utils.connection import Connection
357 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
358 FortiOSHandler,
359 )
360 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
361 check_legacy_fortiosapi,
362 )
363 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
364 schema_to_module_spec,
365 )
366 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
367 check_schema_versioning,
368 )
369 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
370 FAIL_SOCKET_MSG,
371 )
372 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
373 remove_invalid_fields,
374 )
375 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
376 is_same_comparison,
377 )
378 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
379 serialize,
380 )
381 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
382 find_current_values,
383 )
384 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
385 unify_data_format,
386 )
387
388
389 def filter_user_setting_data(json):
390 option_list = [
391 "auth_blackout_time",
392 "auth_ca_cert",
393 "auth_cert",
394 "auth_http_basic",
395 "auth_invalid_max",
396 "auth_lockout_duration",
397 "auth_lockout_threshold",
398 "auth_on_demand",
399 "auth_portal_timeout",
400 "auth_ports",
401 "auth_secure_http",
402 "auth_src_mac",
403 "auth_ssl_allow_renegotiation",
404 "auth_ssl_max_proto_version",
405 "auth_ssl_min_proto_version",
406 "auth_ssl_sigalgs",
407 "auth_timeout",
408 "auth_timeout_type",
409 "auth_type",
410 "cors",
411 "cors_allowed_origins",
412 "default_user_password_policy",
413 "per_policy_disclaimer",
414 "radius_ses_timeout_act",
415 ]
416
417 json = remove_invalid_fields(json)
418 dictionary = {}
419
420 for attribute in option_list:
421 if attribute in json and json[attribute] is not None:
422 dictionary[attribute] = json[attribute]
423
424 return dictionary
425
426
427 def flatten_single_path(data, path, index):
428 if (
429 not data
430 or index == len(path)
431 or path[index] not in data
432 or (not data[path[index]] and not isinstance(data[path[index]], list))
433 ):
434 return
435
436 if index == len(path) - 1:
437 data[path[index]] = " ".join(str(elem) for elem in data[path[index]])
438 if len(data[path[index]]) == 0:
439 data[path[index]] = None
440 elif isinstance(data[path[index]], list):
441 for value in data[path[index]]:
442 flatten_single_path(value, path, index + 1)
443 else:
444 flatten_single_path(data[path[index]], path, index + 1)
445
446
447 def flatten_multilists_attributes(data):
448 multilist_attrs = [
449 ["auth_type"],
450 ]
451
452 for attr in multilist_attrs:
453 flatten_single_path(data, attr, 0)
454
455 return data
456
457
458 def underscore_to_hyphen(data):
459 new_data = None
460 if isinstance(data, list):
461 new_data = []
462 for i, elem in enumerate(data):
463 new_data.append(underscore_to_hyphen(elem))
464 elif isinstance(data, dict):
465 new_data = {}
466 for k, v in data.items():
467 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
468 else:
469 return data
470 return new_data
471
472
473 def user_setting(data, fos, check_mode=False):
474
475 state = None
476 vdom = data["vdom"]
477 parameters = None
478 state = data.get("state", None)
479 user_setting_data = data["user_setting"]
480
481 filtered_data = filter_user_setting_data(user_setting_data)
482 filtered_data = flatten_multilists_attributes(filtered_data)
483 converted_data = underscore_to_hyphen(filtered_data)
484
485 # check_mode starts from here
486 if check_mode:
487 diff = {
488 "before": "",
489 "after": filtered_data,
490 }
491 mkeyname = fos.get_mkeyname(None, None)
492 mkey = fos.get_mkey("user", "setting", filtered_data, vdom=vdom)
493 current_data = fos.get(
494 "user", "setting", vdom=vdom, mkey=mkey, parameters=parameters
495 )
496 is_existed = (
497 current_data
498 and current_data.get("http_status") == 200
499 and (
500 mkeyname
501 and isinstance(current_data.get("results"), list)
502 and len(current_data["results"]) > 0
503 or not mkeyname
504 and current_data["results"] # global object response
505 )
506 )
507
508 # 2. if it exists and the state is 'present' then compare current settings with desired
509 if state == "present" or state is True or state is None:
510 # for non global modules, mkeyname must exist and it's a new module when mkey is None
511 if mkeyname is not None and mkey is None:
512 return False, True, filtered_data, diff
513
514 # if mkey exists then compare each other
515 # record exits and they're matched or not
516 copied_filtered_data = filtered_data.copy()
517 copied_filtered_data.pop(mkeyname, None)
518 unified_filtered_data = unify_data_format(copied_filtered_data)
519
520 current_data_results = current_data.get("results", {})
521 current_config = (
522 current_data_results[0]
523 if mkeyname
524 and isinstance(current_data_results, list)
525 and len(current_data_results) > 0
526 else current_data_results
527 )
528 if is_existed:
529 unified_current_values = find_current_values(
530 unified_filtered_data,
531 unify_data_format(current_config),
532 )
533
534 is_same = is_same_comparison(
535 serialize(unified_current_values), serialize(unified_filtered_data)
536 )
537
538 return (
539 False,
540 not is_same,
541 filtered_data,
542 {"before": unified_current_values, "after": unified_filtered_data},
543 )
544
545 # record does not exist
546 return False, True, filtered_data, diff
547
548 if state == "absent":
549 if mkey is None:
550 return (
551 False,
552 False,
553 filtered_data,
554 {"before": current_data["results"][0], "after": ""},
555 )
556
557 if is_existed:
558 return (
559 False,
560 True,
561 filtered_data,
562 {"before": current_data["results"][0], "after": ""},
563 )
564 return False, False, filtered_data, {}
565
566 return True, False, {"reason: ": "Must provide state parameter"}, {}
567 # pass post processed data to member operations
568 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
569 data_copy = data.copy()
570 data_copy["user_setting"] = filtered_data
571 fos.do_member_operation(
572 "user",
573 "setting",
574 data_copy,
575 )
576
577 return fos.set(
578 "user", "setting", data=converted_data, vdom=vdom, parameters=parameters
579 )
580
581
582 def is_successful_status(resp):
583 return (
584 "status" in resp
585 and resp["status"] == "success"
586 or "http_status" in resp
587 and resp["http_status"] == 200
588 or "http_method" in resp
589 and resp["http_method"] == "DELETE"
590 and resp["http_status"] == 404
591 )
592
593
594 def fortios_user(data, fos, check_mode):
595
596 if data["user_setting"]:
597 resp = user_setting(data, fos, check_mode)
598 else:
599 fos._module.fail_json(msg="missing task body: %s" % ("user_setting"))
600 if isinstance(resp, tuple) and len(resp) == 4:
601 return resp
602 return (
603 not is_successful_status(resp),
604 is_successful_status(resp)
605 and (resp["revision_changed"] if "revision_changed" in resp else True),
606 resp,
607 {},
608 )
609
610
611 versioned_schema = {
612 "v_range": [["v6.0.0", ""]],
613 "type": "dict",
614 "children": {
615 "auth_type": {
616 "v_range": [["v6.0.0", ""]],
617 "type": "list",
618 "options": [
619 {"value": "http"},
620 {"value": "https"},
621 {"value": "ftp"},
622 {"value": "telnet"},
623 ],
624 "multiple_values": True,
625 "elements": "str",
626 },
627 "auth_cert": {"v_range": [["v6.0.0", ""]], "type": "string"},
628 "auth_ca_cert": {"v_range": [["v6.0.0", ""]], "type": "string"},
629 "auth_secure_http": {
630 "v_range": [["v6.0.0", ""]],
631 "type": "string",
632 "options": [{"value": "enable"}, {"value": "disable"}],
633 },
634 "auth_http_basic": {
635 "v_range": [["v6.0.0", ""]],
636 "type": "string",
637 "options": [{"value": "enable"}, {"value": "disable"}],
638 },
639 "auth_ssl_allow_renegotiation": {
640 "v_range": [["v6.0.0", ""]],
641 "type": "string",
642 "options": [{"value": "enable"}, {"value": "disable"}],
643 },
644 "auth_src_mac": {
645 "v_range": [["v6.0.0", ""]],
646 "type": "string",
647 "options": [{"value": "enable"}, {"value": "disable"}],
648 },
649 "auth_on_demand": {
650 "v_range": [["v6.2.0", ""]],
651 "type": "string",
652 "options": [{"value": "always"}, {"value": "implicitly"}],
653 },
654 "auth_timeout": {"v_range": [["v6.0.0", ""]], "type": "integer"},
655 "auth_timeout_type": {
656 "v_range": [["v6.0.0", ""]],
657 "type": "string",
658 "options": [
659 {"value": "idle-timeout"},
660 {"value": "hard-timeout"},
661 {"value": "new-session"},
662 ],
663 },
664 "auth_portal_timeout": {"v_range": [["v6.0.0", ""]], "type": "integer"},
665 "radius_ses_timeout_act": {
666 "v_range": [["v6.0.0", ""]],
667 "type": "string",
668 "options": [{"value": "hard-timeout"}, {"value": "ignore-timeout"}],
669 },
670 "auth_blackout_time": {"v_range": [["v6.0.0", ""]], "type": "integer"},
671 "auth_invalid_max": {"v_range": [["v6.0.0", ""]], "type": "integer"},
672 "auth_lockout_threshold": {"v_range": [["v6.0.0", ""]], "type": "integer"},
673 "auth_lockout_duration": {"v_range": [["v6.0.0", ""]], "type": "integer"},
674 "per_policy_disclaimer": {
675 "v_range": [["v6.2.0", ""]],
676 "type": "string",
677 "options": [{"value": "enable"}, {"value": "disable"}],
678 },
679 "auth_ports": {
680 "type": "list",
681 "elements": "dict",
682 "children": {
683 "id": {
684 "v_range": [["v6.0.0", ""]],
685 "type": "integer",
686 "required": True,
687 },
688 "type": {
689 "v_range": [["v6.0.0", ""]],
690 "type": "string",
691 "options": [
692 {"value": "http"},
693 {"value": "https"},
694 {"value": "ftp"},
695 {"value": "telnet"},
696 ],
697 },
698 "port": {"v_range": [["v6.0.0", ""]], "type": "integer"},
699 },
700 "v_range": [["v6.0.0", ""]],
701 },
702 "auth_ssl_min_proto_version": {
703 "v_range": [["v6.2.0", ""]],
704 "type": "string",
705 "options": [
706 {"value": "default"},
707 {"value": "SSLv3"},
708 {"value": "TLSv1"},
709 {"value": "TLSv1-1"},
710 {"value": "TLSv1-2"},
711 {"value": "TLSv1-3", "v_range": [["v7.4.1", ""]]},
712 ],
713 },
714 "auth_ssl_max_proto_version": {
715 "v_range": [["v7.0.2", ""]],
716 "type": "string",
717 "options": [
718 {"value": "sslv3"},
719 {"value": "tlsv1"},
720 {"value": "tlsv1-1"},
721 {"value": "tlsv1-2"},
722 {"value": "tlsv1-3"},
723 ],
724 },
725 "auth_ssl_sigalgs": {
726 "v_range": [["v7.0.2", ""]],
727 "type": "string",
728 "options": [{"value": "no-rsa-pss"}, {"value": "all"}],
729 },
730 "default_user_password_policy": {"v_range": [["v7.4.1", ""]], "type": "string"},
731 "cors": {
732 "v_range": [["v7.6.3", ""]],
733 "type": "string",
734 "options": [{"value": "disable"}, {"value": "enable"}],
735 },
736 "cors_allowed_origins": {
737 "type": "list",
738 "elements": "dict",
739 "children": {
740 "name": {
741 "v_range": [["v7.6.3", ""]],
742 "type": "string",
743 "required": True,
744 }
745 },
746 "v_range": [["v7.6.3", ""]],
747 },
748 },
749 }
750
751
752 def main():
753 module_spec = schema_to_module_spec(versioned_schema)
754 mkeyname = None
755 fields = {
756 "access_token": {"required": False, "type": "str", "no_log": True},
757 "enable_log": {"required": False, "type": "bool", "default": False},
758 "vdom": {"required": False, "type": "str", "default": "root"},
759 "member_path": {"required": False, "type": "str"},
760 "member_state": {
761 "type": "str",
762 "required": False,
763 "choices": ["present", "absent"],
764 },
765 "user_setting": {
766 "required": False,
767 "type": "dict",
768 "default": None,
769 "options": {},
770 },
771 }
772 for attribute_name in module_spec["options"]:
773 fields["user_setting"]["options"][attribute_name] = module_spec["options"][
774 attribute_name
775 ]
776 if mkeyname and mkeyname == attribute_name:
777 fields["user_setting"]["options"][attribute_name]["required"] = True
778
779 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
780 check_legacy_fortiosapi(module)
781
782 is_error = False
783 has_changed = False
784 result = None
785 diff = None
786
787 versions_check_result = None
788 if module._socket_path:
789 connection = Connection(module._socket_path)
790 if "access_token" in module.params:
791 connection.set_custom_option("access_token", module.params["access_token"])
792
793 if "enable_log" in module.params:
794 connection.set_custom_option("enable_log", module.params["enable_log"])
795 else:
796 connection.set_custom_option("enable_log", False)
797 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
798 versions_check_result = check_schema_versioning(
799 fos, versioned_schema, "user_setting"
800 )
801
802 is_error, has_changed, result, diff = fortios_user(
803 module.params, fos, module.check_mode
804 )
805
806 else:
807 module.fail_json(**FAIL_SOCKET_MSG)
808
809 if versions_check_result and versions_check_result["matched"] is False:
810 module.warn(
811 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
812 )
813
814 if not is_error:
815 if versions_check_result and versions_check_result["matched"] is False:
816 module.exit_json(
817 changed=has_changed,
818 version_check_warning=versions_check_result,
819 meta=result,
820 diff=diff,
821 )
822 else:
823 module.exit_json(changed=has_changed, meta=result, diff=diff)
824 else:
825 if versions_check_result and versions_check_result["matched"] is False:
826 module.fail_json(
827 msg="Error in repo",
828 version_check_warning=versions_check_result,
829 meta=result,
830 )
831 else:
832 module.fail_json(msg="Error in repo", meta=result)
833
834
835 if __name__ == "__main__":
836 main()