From c4af7178b2bfda71c58bad3be09576f53a6d7603 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 16 Jul 2023 17:37:33 +0200 Subject: [PATCH] Add libvirt role --- system/extra/libvirt/meta/argument_specs.yml | 10 +++++ system/extra/libvirt/tasks/main.yml | 45 ++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 system/extra/libvirt/meta/argument_specs.yml create mode 100644 system/extra/libvirt/tasks/main.yml diff --git a/system/extra/libvirt/meta/argument_specs.yml b/system/extra/libvirt/meta/argument_specs.yml new file mode 100644 index 0000000..4d8b67c --- /dev/null +++ b/system/extra/libvirt/meta/argument_specs.yml @@ -0,0 +1,10 @@ +--- +argument_specs: + main: + options: + system_extra_libvirt_user_name: + type: "str" + required: true + system_extra_libvirt_install_zfs_driver: + type: "bool" + required: true diff --git a/system/extra/libvirt/tasks/main.yml b/system/extra/libvirt/tasks/main.yml new file mode 100644 index 0000000..45c410c --- /dev/null +++ b/system/extra/libvirt/tasks/main.yml @@ -0,0 +1,45 @@ +--- +- name: "install libvirt" + ansible.builtin.apt: + name: + - "dnsmasq" + - "libvirt-daemon-system" + - "netcat" + - "qemu-system" + install_recommends: false + register: system_extra_libvirt_install + +- name: "install zfs storage driver for libvirt" + ansible.builtin.apt: + name: + - "libvirt-daemon-driver-storage-zfs" + when: + system_extra_libvirt_install_zfs_driver + register: system_extra_libvirt_zfs_driver + +- name: "enable libvirtd" + ansible.builtin.systemd: + name: "libvirtd" + enabled: true + +- name: "start libvirtd" + ansible.builtin.systemd: + name: "libvirtd" + state: "started" + register: system_extra_libvirt_start + +- name: "restart libvirtd" + ansible.builtin.systemd: + name: "libvirtd" + state: "restarted" + when: + (system_extra_libvirt_install.changed or + (system_extra_libvirt_zfs_driver is defined and + system_extra_libvirt_zfs_driver.changed)) and + not system_extra_libvirt_start.changed + +- name: "add {{ system_extra_libvirt_user_name }} to group \"libvirt\"" + ansible.builtin.user: + name: "{{ system_extra_libvirt_user_name }}" + groups: "libvirt" + append: true