From 12c8d9f55b36c93e758f5587367ec3c810890ac7 Mon Sep 17 00:00:00 2001 From: smirta Date: Fri, 7 Jun 2024 17:26:31 +0200 Subject: [PATCH] feat: better storabe pool creation handling --- roles/libvirt/tasks/main.yml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/roles/libvirt/tasks/main.yml b/roles/libvirt/tasks/main.yml index 2cd7299..f1f8679 100644 --- a/roles/libvirt/tasks/main.yml +++ b/roles/libvirt/tasks/main.yml @@ -8,20 +8,40 @@ become: true - name: Make sure libvirtd is enabled and started - ansible.builtin.systemd_service: + systemd_service: state: started enabled: true name: "{{ libvirt_libvirt_service_name }}" +- name: Check if storage pool {{ libvirt_storage_pool_name }} already exists, do nothing if it does + command: virsh pool-info {{ libvirt_storage_pool_name }} + register: result + ignore_errors: true + - name: Write storage pool definition for {{ libvirt_storage_pool_name }} - ansible.builtin.template: + template: src: templates/storage-pool.xml.j2 dest: /tmp/storage-pool.xml + when: result.rc != 0 - name: Create storage pool {{ libvirt_storage_pool_name }} - command: virsh pool-create /tmp/storage-pool.xml + command: virsh pool-define /tmp/storage-pool.xml + when: result.rc != 0 + +- name: Create storage pool directory {{ libvirt_storage_pool_path }} + command: virsh pool-build {{ libvirt_storage_pool_name }} + when: result.rc != 0 + +- name: Set autostart in storage pool {{ libvirt_storage_pool_name }} + command: virsh pool-autostart {{ libvirt_storage_pool_name }} + when: result.rc != 0 + +- name: Start storage pool {{ libvirt_storage_pool_name }} + command: virsh pool-start {{ libvirt_storage_pool_name }} + when: result.rc != 0 - name: Remove storage pool definition /tmp/storage-pool.xml file: path: /tmp/storage-pool.xml state: absent + when: result.rc != 0