From 0c08a276585a00a62974981ade09077aee51be40 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 15:55:16 +0400 Subject: [PATCH] remove backup_dir --- plugins/modules/logrotate.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/plugins/modules/logrotate.py b/plugins/modules/logrotate.py index 185676c7e5..c7cf8a74fe 100644 --- a/plugins/modules/logrotate.py +++ b/plugins/modules/logrotate.py @@ -253,11 +253,6 @@ options: description: - Make a backup of the logrotate config file before changing it. type: bool - backup_dir: - description: - - Directory to store backup files. - - Default is same as O(config_dir) with V(.backup) suffix. - type: path start: description: - Base number for rotated files. @@ -455,7 +450,7 @@ backup_file: description: Path to the backup file if backup was created. type: str returned: when backup was created - sample: /etc/logrotate.d/nginx.backup.20231201 + sample: /etc/logrotate.d/nginx.backup enabled_state: description: Current enabled state of the configuration. type: bool @@ -784,20 +779,16 @@ class LogrotateConfig: return None if self.params.get("backup"): - backup_dir = self.params.get("backup_dir") or os.path.join(self.config_dir, ".backup") - if not os.path.exists(backup_dir): + try: + # Используем встроенный механизм Ansible для создания бэкапа + backup_file = self.module.backup_local(config_path) + self.result["backup_file"] = backup_file + return backup_file + except Exception as e: self.module.fail_json( - msg=f"Backup directory '{backup_dir}' does not exist. " - f"Please create it manually if you want to use backup feature." + msg=f"Failed to create backup of {config_path}: {to_native(e)}" ) - - timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") - backup_file = os.path.join(backup_dir, f"{self.config_name}.backup.{timestamp}") - - self.module.atomic_move(config_path, backup_file, unsafe_writes=False) - self.result["backup_file"] = backup_file - return backup_file - + return None def apply(self) -> dict[str, object]: @@ -952,7 +943,6 @@ def main() -> None: tabooext=dict(type="list", elements="str"), enabled=dict(type="bool"), backup=dict(type="bool"), - backup_dir=dict(type="path"), start=dict(type="int"), syslog=dict(type="bool"), ),