From aa64ba98b51ab884c38ef819aa948da2f2855af9 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Fri, 15 Sep 2023 00:31:55 +0200 Subject: [PATCH] fix: speed up destroy by not using `stat` (#17) --- tasks/destroy_virtual_machine.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tasks/destroy_virtual_machine.yml b/tasks/destroy_virtual_machine.yml index 527023d..148cdb1 100644 --- a/tasks/destroy_virtual_machine.yml +++ b/tasks/destroy_virtual_machine.yml @@ -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 @@ -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