summaryrefslogtreecommitdiff
path: root/roles/vm/guest/remove/tasks/main.yml
blob: c0fb66d0d2c6cf8ae7b92271b8ec5169f5c2448a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
---
- name: check if vm already exists
  delegate_to: "{{ vm_host.name }}"
  virt:
    name: "{{ inventory_hostname }}"
    command: info
  register: vmhost_info

- name: remove old vm
  when: inventory_hostname in vmhost_info
  delegate_to: "{{ vm_host.name }}"
  block:
  - name: destroy exisiting vm
    virt:
      name: "{{ inventory_hostname }}"
      state: destroyed

  - name: wait for vm to be destroyed
    wait_for_virt:
      name: "{{ inventory_hostname }}"
      states: shutdown,crashed
      timeout: 5

  - name: undefining exisiting vm
    virt_with_undefineflags: ## TODO: switch back to virt once this lands: https://github.com/ansible-collections/community.libvirt/pull/136
      name: "{{ inventory_hostname }}"
      command: undefine
      flags: "{{ vm_remove_undefine_flags | default(omit) }}"