From 21679647c6e93dcd7cfef9c9e96689bfcb5b1d7f Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 5 Sep 2022 00:33:46 +1200 Subject: [PATCH] libvirt role --- .../roles/libvirt-server/defaults/main.yml | 13 +++ ansible/roles/libvirt-server/tasks/main.yml | 92 +++++++++++++++++++ .../roles/libvirt-server/templates/iso.xml.j2 | 17 ++++ .../libvirt-server/templates/network.xml.j2 | 12 +++ .../libvirt-server/templates/qcow.xml.j2 | 0 .../roles/libvirt-server/templates/zfs.xml.j2 | 13 +++ 6 files changed, 147 insertions(+) create mode 100644 ansible/roles/libvirt-server/defaults/main.yml create mode 100644 ansible/roles/libvirt-server/tasks/main.yml create mode 100644 ansible/roles/libvirt-server/templates/iso.xml.j2 create mode 100644 ansible/roles/libvirt-server/templates/network.xml.j2 create mode 100644 ansible/roles/libvirt-server/templates/qcow.xml.j2 create mode 100644 ansible/roles/libvirt-server/templates/zfs.xml.j2 diff --git a/ansible/roles/libvirt-server/defaults/main.yml b/ansible/roles/libvirt-server/defaults/main.yml new file mode 100644 index 0000000..5d40a60 --- /dev/null +++ b/ansible/roles/libvirt-server/defaults/main.yml @@ -0,0 +1,13 @@ +--- +libvirt_server_packages: + - qemu-base + - libvirt + - bridge-utils + - openbsd-netcat + - edk2-ovmf + - swtpm + +libvirt_zfs_pool_name: zfs +libvirt_iso_pool_name: iso +libvirt_qcow_pool_name: qcow +libvirt_vm_network_name: br22 \ No newline at end of file diff --git a/ansible/roles/libvirt-server/tasks/main.yml b/ansible/roles/libvirt-server/tasks/main.yml new file mode 100644 index 0000000..9602672 --- /dev/null +++ b/ansible/roles/libvirt-server/tasks/main.yml @@ -0,0 +1,92 @@ +--- +- name: install libvirt server packages + become: true + community.general.pacman: + name: "{{ libvirt_server_packages }}" + state: latest + update_cache: true + reason: explicit + when: + - ansible_os_family == 'Arch' + +- name: add user to libvirt group + become: true + ansible.builtin.user: + name: "{{ ansible_user }}" + groups: libvirt + append: true + +- name: start and enable libvirt service + become: true + ansible.builtin.service: + name: libvirtd.service + state: started + enabled: yes + +- name: define vm network + community.libvirt.virt_net: + name: "{{ libvirt_vm_network_name }}" + command: define + xml: '{{ lookup("template", "network.xml.j2") }}' + +- name: build vm network + community.libvirt.virt_net: + name: "{{ libvirt_vm_network_name }}" + command: build + +- name: start vm network + community.libvirt.virt_net: + name: "{{ libvirt_vm_network_name }}" + state: active + autostart: true + +- name: define zfs storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_zfs_pool_name }}" + command: define + xml: '{{ lookup("template", "zfs.xml.j2") }}' + +- name: build zfs storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_zfs_pool_name }}" + command: build + +- name: start zfs storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_zfs_pool_name }}" + state: active + autostart: true + +- name: define iso storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_iso_pool_name }}" + command: define + xml: '{{ lookup("template", "iso.xml.j2") }}' + +- name: build iso storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_iso_pool_name }}" + command: build + +- name: start iso storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_iso_pool_name }}" + state: active + autostart: true + +- name: define qcow storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_qcow_pool_name }}" + command: define + xml: '{{ lookup("template", "qcow.xml.j2") }}' + +- name: build qcow storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_qcow_pool_name }}" + command: build + +- name: start qcow storage pool + community.libvirt.virt_pool: + name: "{{ libvirt_qcow_pool_name }}" + state: active + autostart: true \ No newline at end of file diff --git a/ansible/roles/libvirt-server/templates/iso.xml.j2 b/ansible/roles/libvirt-server/templates/iso.xml.j2 new file mode 100644 index 0000000..f39f621 --- /dev/null +++ b/ansible/roles/libvirt-server/templates/iso.xml.j2 @@ -0,0 +1,17 @@ + + iso + c7be6440-728c-4181-b7e8-68bf3094740a + 208525328384 + 31027101696 + 177498226688 + + + + /mnt/smb/isos + + 0755 + 1000 + 1000 + + + \ No newline at end of file diff --git a/ansible/roles/libvirt-server/templates/network.xml.j2 b/ansible/roles/libvirt-server/templates/network.xml.j2 new file mode 100644 index 0000000..2827dae --- /dev/null +++ b/ansible/roles/libvirt-server/templates/network.xml.j2 @@ -0,0 +1,12 @@ + + default + ea5ab2e3-1c95-49de-af3b-131a836f4b7b + + + + + + + + + \ No newline at end of file diff --git a/ansible/roles/libvirt-server/templates/qcow.xml.j2 b/ansible/roles/libvirt-server/templates/qcow.xml.j2 new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/libvirt-server/templates/zfs.xml.j2 b/ansible/roles/libvirt-server/templates/zfs.xml.j2 new file mode 100644 index 0000000..9a03618 --- /dev/null +++ b/ansible/roles/libvirt-server/templates/zfs.xml.j2 @@ -0,0 +1,13 @@ + + zfs-nvme + 026cccc9-ee79-467a-bf19-91e6f3d2531d + 498216206336 + 185811460096 + 312404746240 + + nvme/vhds + + + /dev/zvol/nvme/vhds + +