hcloud_volume attach step should be idempotent (#56906)

This commit is contained in:
Lukas Kämmerling 2019-05-27 07:48:48 +02:00 committed by René Moser
parent 8f89d1d3da
commit 7f08de6b6c
3 changed files with 16 additions and 5 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- hcloud_volume - Fix idempotency when attaching a server to a volume.

View file

@ -232,7 +232,7 @@ class AnsibleHcloudVolume(Hcloud):
server_name = self.module.params.get("server") server_name = self.module.params.get("server")
if server_name: if server_name:
server = self.client.servers.get_by_name(server_name) server = self.client.servers.get_by_name(server_name)
if self.hcloud_volume.server != server: if self.hcloud_volume.server is None or self.hcloud_volume.server.name != server.name:
if not self.module.check_mode: if not self.module.check_mode:
automount = self.module.params.get("automount", False) automount = self.module.params.get("automount", False)
self.hcloud_volume.attach(server, automount=automount).wait_until_finished() self.hcloud_volume.attach(server, automount=automount).wait_until_finished()

View file

@ -8,11 +8,11 @@
image: ubuntu-18.04 image: ubuntu-18.04
state: started state: started
location: "fsn1" location: "fsn1"
register: main_server register: vol_server
- name: verify setup server - name: verify setup server
assert: assert:
that: that:
- main_server is changed - vol_server is changed
- name: test missing size parameter on create Volume - name: test missing size parameter on create Volume
hcloud_volume: hcloud_volume:
@ -86,7 +86,17 @@
that: that:
- volume is changed - volume is changed
- volume.hcloud_volume.server == "{{hcloud_server_name}}" - volume.hcloud_volume.server == "{{hcloud_server_name}}"
- main_server is changed
- name: test attach volume idempotence
hcloud_volume:
name: "{{hcloud_volume_name}}"
server: "{{hcloud_server_name}}"
register: volume
- name: verify attach volume idempotence
assert:
that:
- volume is not changed
- volume.hcloud_volume.server == "{{hcloud_server_name}}"
- name: test detach volume with checkmode - name: test detach volume with checkmode
hcloud_volume: hcloud_volume:
@ -109,7 +119,6 @@
- volume is changed - volume is changed
- volume.hcloud_volume.location == "fsn1" - volume.hcloud_volume.location == "fsn1"
- volume.hcloud_volume.server != "{{hcloud_server_name}}" - volume.hcloud_volume.server != "{{hcloud_server_name}}"
- main_server is changed
- name: test update volume label - name: test update volume label
hcloud_volume: hcloud_volume: