From d5d57426d557470b28834c195d593b75b8fd9a47 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 23 Apr 2021 14:54:03 +0200 Subject: [PATCH] copr-hv: auto-create libvirt image pool --- roles/copr/hypervisor/tasks/main.yml | 24 ++++++++++++++++++- .../templates/libvirt-pool-images.xml | 6 +++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 roles/copr/hypervisor/templates/libvirt-pool-images.xml diff --git a/roles/copr/hypervisor/tasks/main.yml b/roles/copr/hypervisor/tasks/main.yml index 6702453c7f..204de9c327 100644 --- a/roles/copr/hypervisor/tasks/main.yml +++ b/roles/copr/hypervisor/tasks/main.yml @@ -19,7 +19,7 @@ - libvirtd - config -- set_fact: image_pool_dir=/libvirt-images +- set_fact: image_pool_dir=/libvirt-images image_pool_name=images tags: libvirtd - name: create libvirt image directory @@ -68,6 +68,28 @@ notify: restart libvirtd tags: libvirtd +- name: check if image pool exists + shell: virsh pool-info "{{ image_pool_name }}" + register: libvirt_pool_exists + failed_when: false + changed_when: libvirt_pool_exists.rc != 0 + tags: libvirtd + +- name: copy image pool config file to host + template: src=libvirt-image-pool.xml + dest=/root/.tmp-ansible-file.xml + when: libvirt_pool_exists.changed + tags: libvirtd + +- name: define image pool in libvirt + shell: | + virsh pool-define /root/.tmp-ansible-file.xml + virsh pool-start "{{ image_pool_name }}" + virsh pool-autostart "{{ image_pool_name }}" + when: libvirt_pool_exists.changed + notify: restart libvirtd + tags: libvirtd + - name: allow copr user controlling libvirt ini_file: path: /usr/lib/systemd/system/libvirtd.socket diff --git a/roles/copr/hypervisor/templates/libvirt-pool-images.xml b/roles/copr/hypervisor/templates/libvirt-pool-images.xml new file mode 100644 index 0000000000..1c87d6b7a5 --- /dev/null +++ b/roles/copr/hypervisor/templates/libvirt-pool-images.xml @@ -0,0 +1,6 @@ + + {{ image_pool_name }} + + {{ image_pool_dir }} + +