1
0
IaC/ansible/roles/hypervisor_qcow/tasks/libvirt_dir.yaml

62 lines
1.4 KiB
YAML
Raw Normal View History

2023-08-10 09:32:17 -04:00
---
- name: Format and mount the libvirt disk if it is not root
2023-08-10 11:11:37 -04:00
when:
- hypervisor.device not in (ansible_mounts | json_query('[?mount == `/`].device'))
- hypervisor.device not in (ansible_mounts | json_query('[?mount == `/var/lib/libvirt`].device'))
2023-08-10 09:32:17 -04:00
ansible.builtin.include_tasks:
file: libvirt_mount.yaml
2023-08-10 11:11:37 -04:00
- name: Create the libvirt storage directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: libvirt-qemu
group: libvirt-qemu
mode: '0775'
loop:
- /var/lib/libvirt/vhds/
- /var/lib/libvirt/isos/
- /var/lib/libvirt/nvram/
- name: Remove the default libvirt storage pool
community.libvirt.virt_pool:
name: default
state: deleted
- name: Get libvirt storage pool facts
community.libvirt.virt_pool:
command: facts
- name: Define the libvirt storage pools
community.libvirt.virt_pool:
name: "{{ item.name }}"
command: define
xml: "{{ lookup('template', 'dir_pool.xml.j2') }}"
loop:
- name: vhds
path: /var/lib/libvirt/vhds/
- name: isos
path: /var/lib/libvirt/isos/
- name: nvram
path: /var/lib/libvirt/nvram/
- name: Create the libvirt storage pools
community.libvirt.virt_pool:
name: "{{ item }}"
command: build
loop:
- vhds
- isos
- nvram
- name: Start the libvirt storage pools
community.libvirt.virt_pool:
name: "{{ item }}"
state: active
autostart: true
loop:
- vhds
- isos
- nvram