1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

remove backup_dir

This commit is contained in:
Александр Габидуллин 2026-01-29 15:55:16 +04:00
parent f2af2df604
commit 0c08a27658

View file

@ -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"),
),