1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

fix(server): prevent backups from being disabled when undefined (#196)

* fix(server): prevent backups from being disabled when undefined

With an existing server with backups enabled and the state being either
present, started, stopped, restarted or rebuild and the backups module
parameter not set, the module would disable backups and in turn delete
all existing backups.

The correct behaviour (leave backups untouched when parameter not set)
is implemented by this commit. Strong typing would have prevented this.

* test: verify fix works

---------

Co-authored-by: Julian Tölle <julian.toelle@hetzner-cloud.de>
This commit is contained in:
lrsksr 2023-04-03 12:36:33 +02:00 committed by GitHub
parent 43ae035040
commit 25bce7eabd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- hcloud_server - Prevent backups from being disabled when undefined

View file

@ -585,11 +585,12 @@ class AnsibleHcloudServer(Hcloud):
self.hcloud_server.disable_rescue().wait_until_finished()
self._mark_as_changed()
if self.module.params.get("backups") and self.hcloud_server.backup_window is None:
backups = self.module.params.get("backups")
if backups and self.hcloud_server.backup_window is None:
if not self.module.check_mode:
self.hcloud_server.enable_backup().wait_until_finished()
self._mark_as_changed()
elif not self.module.params.get("backups") and self.hcloud_server.backup_window is not None:
elif backups is not None and not backups and self.hcloud_server.backup_window is not None:
if not self.module.check_mode:
self.hcloud_server.disable_backup().wait_until_finished()
self._mark_as_changed()

View file

@ -214,6 +214,21 @@
- result is not changed
- result.hcloud_server.backup_window != ""
- name: test backups are not accidentally disabled
hcloud_server:
name: "{{ hcloud_server_name }}"
# Make sure that backups are not disabled because a partial server object without "backups" was supplied somewhere
# to update some unrelated properties.
# Regression test for https://github.com/ansible-collections/hetzner.hcloud/pull/196
# backups: true
state: stopped
register: result
- name: verify backups are not accidentally disabled
assert:
that:
- result is not changed
- result.hcloud_server.backup_window != ""
- name: test rebuild server
hcloud_server:
name: "{{ hcloud_server_name }}"

View file

@ -2,7 +2,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
#- ansible.builtin.include_tasks: validation.yml
#- ansible.builtin.include_tasks: basic.yml
- ansible.builtin.include_tasks: basic.yml
#- ansible.builtin.include_tasks: firewalls.yml
- ansible.builtin.include_tasks: primary_ips.yml
- ansible.builtin.include_tasks: private_network_only.yml