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

75 lines
1.5 KiB
YAML
Raw Normal View History

2023-08-10 11:11:37 -04:00
---
- name: Configure disk partition
community.general.parted:
align: optimal
device: "{{ hypervisor.device }}"
fs_type: ext4
label: gpt
name: libvirt
number: 1
part_end: 100%
part_start: 0%
state: present
- name: Format filesystem
community.general.filesystem:
device: "{{ hypervisor.device }}1"
fstype: ext4
resizefs: true
state: present
- name: Stop the libvirt service
ansible.builtin.service:
name: libvirtd
state: stopped
- name: Temp mount and copy block
block:
- name: Temporarily mount hypervisor storage
ansible.posix.mount:
path: /mnt/libvirt_temp/
src: "{{ hypervisor.device }}1"
fstype: ext4
state: mounted
boot: false
- name: Copy libvirt contents to hypervisor storage
ansible.builtin.copy:
src: /var/lib/libvirt/
dest: /mnt/libvirt_temp/
remote_src: true
mode: preserve
always:
- name: Unmount from temporary mount point
ansible.posix.mount:
path: /mnt/libvirt_temp/
state: absent
- name: Remove existing libvirt storage
ansible.builtin.file:
path: /var/lib/libvirt/
state: "{{ item }}"
owner: root
group: root
mode: '0775'
loop:
- absent
- directory
- name: Mount hypervisor storage
ansible.posix.mount:
path: /var/lib/libvirt/
src: "{{ hypervisor.device }}1"
fstype: ext4
state: mounted
boot: true
- name: Start the libvirt service
ansible.builtin.service:
name: libvirtd
state: started