From 8fb7bf8d6830b77192f6481df1b78f5f54d2b4f0 Mon Sep 17 00:00:00 2001 From: Roberto Alfieri Date: Thu, 1 Aug 2024 15:18:06 +0200 Subject: [PATCH] [nat64_appliance] Check if virtqemud socket exists during the cleanup Since most of the cleanup operations are performed via libvirt, we are going to test if the service is up checking for the existance of the `virtqemud` socket. --- roles/nat64_appliance/tasks/cleanup.yml | 82 ++++++++++++++----------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/roles/nat64_appliance/tasks/cleanup.yml b/roles/nat64_appliance/tasks/cleanup.yml index 9bc0dc02c3..f58b4cc8af 100644 --- a/roles/nat64_appliance/tasks/cleanup.yml +++ b/roles/nat64_appliance/tasks/cleanup.yml @@ -19,44 +19,52 @@ state: absent path: "{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2" -- name: List VMs - register: _list_vms - community.libvirt.virt: - command: list_vms +- name: Get virtqemud socket + register: _virtqemud + ansible.builtin.stat: + path: "/var/run/libvirt/virtqemud-sock" -- name: Stop the nat64_appliance VM - when: cifmw_nat64_appliance_name in _list_vms.list_vms - community.libvirt.virt: - command: destroy - name: "{{ cifmw_nat64_appliance_name }}" - uri: "{{ cifmw_nat64_libvirt_uri }}" +- name: Perform the nat64_appliance cleanup in libvirt + when: _virtqemud.stat.exists + block: + - name: List VMs + register: _list_vms + community.libvirt.virt: + command: list_vms -- name: Undefine the nat64_appliance VM - when: cifmw_nat64_appliance_name in _list_vms.list_vms - community.libvirt.virt: - command: undefine - name: "{{ cifmw_nat64_appliance_name }}" - force: true - uri: "{{ cifmw_nat64_libvirt_uri }}" + - name: Stop the nat64_appliance VM + when: cifmw_nat64_appliance_name in _list_vms.list_vms + community.libvirt.virt: + command: destroy + name: "{{ cifmw_nat64_appliance_name }}" + uri: "{{ cifmw_nat64_libvirt_uri }}" -- name: Destroy the nat64 networks - register: net_destroy - community.libvirt.virt_net: - command: destroy - name: "{{ item }}" - uri: "{{ cifmw_nat64_libvirt_uri }}" - loop: - - "{{ cifmw_nat64_network_ipv4_name }}" - - "{{ cifmw_nat64_network_ipv6_name }}" - failed_when: - - net_destroy.rc is defined - - net_destroy.rc > 1 + - name: Undefine the nat64_appliance VM + when: cifmw_nat64_appliance_name in _list_vms.list_vms + community.libvirt.virt: + command: undefine + name: "{{ cifmw_nat64_appliance_name }}" + force: true + uri: "{{ cifmw_nat64_libvirt_uri }}" -- name: Undefine the nat64 networks - community.libvirt.virt_net: - command: undefine - name: "{{ item }}" - uri: "{{ cifmw_nat64_libvirt_uri }}" - loop: - - "{{ cifmw_nat64_network_ipv4_name }}" - - "{{ cifmw_nat64_network_ipv6_name }}" + - name: Destroy the nat64 networks + register: net_destroy + community.libvirt.virt_net: + command: destroy + name: "{{ item }}" + uri: "{{ cifmw_nat64_libvirt_uri }}" + loop: + - "{{ cifmw_nat64_network_ipv4_name }}" + - "{{ cifmw_nat64_network_ipv6_name }}" + failed_when: + - net_destroy.rc is defined + - net_destroy.rc > 1 + + - name: Undefine the nat64 networks + community.libvirt.virt_net: + command: undefine + name: "{{ item }}" + uri: "{{ cifmw_nat64_libvirt_uri }}" + loop: + - "{{ cifmw_nat64_network_ipv4_name }}" + - "{{ cifmw_nat64_network_ipv6_name }}"