Skip to content

Commit

Permalink
fix: speed up destroy by not using stat (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPsychick authored Sep 14, 2023
1 parent f1bf0d9 commit aa64ba9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tasks/destroy_virtual_machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
failed_when: false

- name: Check for image
ansible.builtin.stat:
ansible.builtin.file:
path: "{{ libvirt_image_dir }}/{{ instance.name }}.qcow2"
state: file
register: image_file
failed_when: false

- name: Delete image (volume)
ansible.builtin.shell: virsh vol-delete {{ instance.name }}.qcow2 --pool {{ libvirt_disk_pool }}
when: image_file.stat.exists and instance.disk_image is not defined
when: image_file.state != "absent" and instance.disk_image is not defined
failed_when: false
tags:
- skip_ansible_lint
Expand All @@ -27,7 +29,7 @@
ansible.builtin.file:
path: "{{ libvirt_image_dir }}/{{ instance.name }}.qcow2"
state: absent
when: image_file.stat.exists and instance.disk_image is defined
when: image_file.state != "absent" and instance.disk_image is defined
failed_when: false

- name: Delete directory
Expand Down

0 comments on commit aa64ba9

Please sign in to comment.