vm/install: Group conditional when destroying existing VMs
authornicoo <nicoo@realraum.at>
Wed, 13 Jun 2018 01:54:52 +0000 (03:54 +0200)
committernicoo <nicoo@realraum.at>
Sun, 17 Jun 2018 10:03:51 +0000 (12:03 +0200)
ansible/roles/vm/install/tasks/main.yml

index 505ec1d..39e625f 100644 (file)
     command: info
   register: vmhost_info
 
-- name: destroy exisiting vm
-  virt:
-    name: "{{ vmname }}"
-    state: destroyed
-  when: vmname in vmhost_info
-
-- name: wait for vm to be destroyed
-  wait_for_virt:
-    name: "{{ vmname }}"
-    states: shutdown,crashed
-    timeout: 5
-  when: vmname in vmhost_info
+- block:
+    - name: destroy exisiting vm
+      virt:
+        name: "{{ vmname }}"
+        state: destroyed
+
+    - name: wait for vm to be destroyed
+      wait_for_virt:
+        name: "{{ vmname }}"
+        states: shutdown,crashed
+        timeout: 5
+
+    - name: undefining exisiting vm
+      virt:
+        name: "{{ vmname }}"
+        command: undefine
 
-- name: undefining exisiting vm
-  virt:
-    name: "{{ vmname }}"
-    command: undefine
   when: vmname in vmhost_info
 
 - name: enable installer in VM config