From fb97523bd37a7e1c849211cd25807bdeca710e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=93=D0=B0=D0=B1=D0=B8=D0=B4=D1=83=D0=BB=D0=BB=D0=B8=D0=BD?= Date: Thu, 29 Jan 2026 17:01:25 +0400 Subject: [PATCH] 1 --- plugins/modules/logrotate.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/modules/logrotate.py b/plugins/modules/logrotate.py index c659ea0b53..f084e527b0 100644 --- a/plugins/modules/logrotate.py +++ b/plugins/modules/logrotate.py @@ -459,9 +459,10 @@ from ansible.module_utils.common.text.converters import to_native class LogrotateConfig: """Logrotate configuration manager.""" - def __init__(self, module: AnsibleModule) -> None: + def __init__(self, module: AnsibleModule, logrotate_bin: str) -> None: self.module = module self.params = module.params + self.logrotate_bin = logrotate_bin self.result: dict[str, object] = { "changed": False, "config_file": "", @@ -849,8 +850,8 @@ class LogrotateConfig: msg=f"Failed to write config file {self.result['config_file']}: {to_native(e)}" ) - if self.module.get_bin_path("logrotate"): - test_cmd = ["logrotate", "-d", str(self.result["config_file"])] + if not self.module.check_mode: + test_cmd = [self.logrotate_bin, "-d", str(self.result["config_file"])] rc, stdout, stderr = self.module.run_command(test_cmd) if rc != 0: self.module.warn(f"logrotate configuration test failed: {stderr}") @@ -918,9 +919,8 @@ def main() -> None: supports_check_mode=True, ) - if not module.get_bin_path("logrotate"): - module.fail_json(msg="logrotate is not installed or not in PATH") - logrotate_config = LogrotateConfig(module) + logrotate_bin = module.get_bin_path("logrotate", required=True) + logrotate_config = LogrotateConfig(module, logrotate_bin) result = logrotate_config.apply() module.exit_json(**result)