hypervisor wip
This commit is contained in:
parent
84a20416e3
commit
2769a3430b
@ -1,8 +1,61 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: Format and mount the libvirt disk if it is not root
|
- name: Format and mount the libvirt disk if it is not root
|
||||||
when: hypervisor.device not in (ansible_mounts | json_query('[?mount == `/`].device'))
|
when:
|
||||||
|
- hypervisor.device not in (ansible_mounts | json_query('[?mount == `/`].device'))
|
||||||
|
- hypervisor.device not in (ansible_mounts | json_query('[?mount == `/var/lib/libvirt`].device'))
|
||||||
ansible.builtin.include_tasks:
|
ansible.builtin.include_tasks:
|
||||||
file: libvirt_mount.yaml
|
file: libvirt_mount.yaml
|
||||||
|
|
||||||
|
- 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
|
||||||
|
74
ansible/roles/hypervisor_qcow/tasks/libvirt_mount.yaml
Normal file
74
ansible/roles/hypervisor_qcow/tasks/libvirt_mount.yaml
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- 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
|
@ -13,6 +13,16 @@
|
|||||||
groups: libvirt
|
groups: libvirt
|
||||||
append: true
|
append: true
|
||||||
|
|
||||||
|
- name: Set required sysctl flags for bridging
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
value: "{{ item.value }}}}"
|
||||||
|
state: present
|
||||||
|
sysctl_set: true
|
||||||
|
reload: true # TODO set sysctl file?
|
||||||
|
loop:
|
||||||
|
- net.ipv4.ip_forward # TODO add remaining values here
|
||||||
|
|
||||||
- name: Add bridge(s) to qemu_bridge_helper
|
- name: Add bridge(s) to qemu_bridge_helper
|
||||||
when: qemu_bridges is defined
|
when: qemu_bridges is defined
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
@ -39,7 +49,7 @@
|
|||||||
name: default
|
name: default
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Setup libvirt storage (qcow)
|
- name: Setup libvirt storage (dir)
|
||||||
when: hypervisor.storage == 'dir'
|
when: hypervisor.storage == 'dir'
|
||||||
ansible.builtin.include_tasks:
|
ansible.builtin.include_tasks:
|
||||||
file: libvirt_dir.yaml
|
file: libvirt_dir.yaml
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
<pool type="dir">
|
||||||
|
<name>{{ item.name }}</name>
|
||||||
|
<target>
|
||||||
|
<path>{{ item.path }}</path>
|
||||||
|
</target>
|
||||||
|
</pool>
|
@ -0,0 +1,6 @@
|
|||||||
|
<pool type="zfs">
|
||||||
|
<name>{{ item.name }}</name>
|
||||||
|
<source>
|
||||||
|
<name>{{ item.dataset }}</name>
|
||||||
|
</source>
|
||||||
|
</pool>
|
Loading…
Reference in New Issue
Block a user