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