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
|
|
|
|
|
2023-08-14 08:27:29 -04:00
|
|
|
# TODO disk encryption
|
|
|
|
|
2023-08-10 11:11:37 -04:00
|
|
|
- name: Format filesystem
|
|
|
|
community.general.filesystem:
|
|
|
|
device: "{{ hypervisor.device }}1"
|
|
|
|
fstype: ext4
|
|
|
|
resizefs: true
|
|
|
|
state: present
|
|
|
|
|
2023-08-14 08:27:29 -04:00
|
|
|
- name: Get list of services
|
|
|
|
ansible.builtin.service_facts:
|
|
|
|
|
|
|
|
- name: Stop the libvirt services
|
|
|
|
when: item in ansible_facts.services
|
2023-08-10 11:11:37 -04:00
|
|
|
ansible.builtin.service:
|
2023-08-14 08:27:29 -04:00
|
|
|
name: "{{ item }}"
|
2023-08-10 11:11:37 -04:00
|
|
|
state: stopped
|
2023-08-14 08:27:29 -04:00
|
|
|
loop:
|
|
|
|
- libvirtd.service
|
|
|
|
|
|
|
|
- name: Check if libvirt storage directory exists
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: /var/lib/libvirt/
|
|
|
|
register: libvirt_storage
|
2023-08-10 11:11:37 -04:00
|
|
|
|
|
|
|
- name: Temp mount and copy block
|
2023-08-14 08:27:29 -04:00
|
|
|
when: libvirt_storage.stat.exists
|
2023-08-10 11:11:37 -04:00
|
|
|
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
|
|
|
|
|
2023-08-14 08:27:29 -04:00
|
|
|
- name: Remove existing libvirt storage
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /var/lib/libvirt/
|
|
|
|
state: "{{ item }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0775'
|
|
|
|
loop:
|
|
|
|
- absent
|
|
|
|
- directory
|
|
|
|
|
2023-08-10 11:11:37 -04:00
|
|
|
always:
|
|
|
|
|
|
|
|
- name: Unmount from temporary mount point
|
|
|
|
ansible.posix.mount:
|
|
|
|
path: /mnt/libvirt_temp/
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- 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
|
2023-08-14 08:27:29 -04:00
|
|
|
when: item in ansible_facts.services
|
2023-08-10 11:11:37 -04:00
|
|
|
ansible.builtin.service:
|
2023-08-14 08:27:29 -04:00
|
|
|
name: "{{ item }}"
|
2023-08-10 11:11:37 -04:00
|
|
|
state: started
|
2023-08-14 08:27:29 -04:00
|
|
|
loop:
|
|
|
|
- libvirtd.service
|