Add libvirt role

This commit is contained in:
Wojciech Kozlowski 2023-07-16 17:37:33 +02:00
parent 403b65f812
commit c4af7178b2
2 changed files with 55 additions and 0 deletions

View File

@ -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

View File

@ -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