mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
1
This commit is contained in:
parent
510d5237cd
commit
fb97523bd3
1 changed files with 6 additions and 6 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue