Skip to content

Commit 54cf2cc

Browse files
authored
Merge pull request #84 from stackhpc/efi-undefine
Fix undefining libvirt VMs with EFI boot firmware
2 parents 3702892 + 021942d commit 54cf2cc

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tasks/destroy-vm.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@
1717
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
1818
become: yes
1919

20+
# note(wszumski): the virt module does not seem to support
21+
# removing vms with nvram defined - as a workaround, use the
22+
# virsh cli directly. It may be better to detect if dumpxml
23+
# actually contains an nvram element rather than relying on
24+
# boot_firmware having the correct value.
2025
- name: Ensure the VM is undefined
21-
virt:
22-
name: "{{ vm.name }}"
23-
command: undefine
24-
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
26+
command:
27+
cmd: >-
28+
virsh
29+
{% if libvirt_vm_uri %}-c {{ libvirt_vm_uri }}{% endif %}
30+
undefine
31+
{% if boot_firmware == 'efi' %} --nvram{% endif %}
32+
{{ vm.name }}
2533
become: yes
34+
changed_when: true
2635
when: vm.name in result.list_vms

tasks/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
when: (vm.state | default('present', true)) == 'present'
5353

5454
- include_tasks: destroy-vm.yml
55+
vars:
56+
boot_firmware: "{{ vm.boot_firmware | default('bios', true) | lower }}"
5557
with_items: "{{ libvirt_vms }}"
5658
loop_control:
5759
loop_var: vm

0 commit comments

Comments
 (0)