Install, configure and provision libvirt resources.
GitLab project: yoanncolin/ansible/roles/libvirt
With no variable set, the role installs libvirt with its QEMU backend and leaves the configuration your distribution ships as it is, but for what makes it usable right away:
- the
defaultNAT network is started and set to autostart, and thedefaultstorage pool is created on/var/lib/libvirt/images, so a domain gets a network and a disk without further setup; - where the distribution's packages do not work out of the box, the role fixes what stops them, and nothing more — on Debian 12, the system dnsmasq is bound to its own interfaces so that it leaves libvirt's networks alone.
One more change is made today and is on its way out, because nothing needs
it: the QEMU security driver written in qemu.conf.
Everything else happens only when You describe it.
The Linux base system configured with:
- SSH
- Python (for Ansible)
- Sudo
- Package manager ready to use
The gwerlas.system role can help You:
ansible-galaxy install gwerlas.system- name: My playbook
hosts: all
roles:
- role: gwerlas.system
- role: gwerlas.libvirtYou can filter on some specific tasks using this tags:
provision: Provision resources onlyusers: Set users environment and permissions (groups, per-user resources and TLS credentials)ca: Redeploy the CA certificate and restart the daemon to apply itssl: Redeploy the server/client certificates and restart the daemon to apply them
| Variable | Default | Description |
|---|---|---|
libvirt_backends |
[qemu] |
List of backends to install |
libvirt_install |
[libvirtd, clients] |
Components to install (libvirtd, clients, virt-manager, gnome-boxes, qemu) |
libvirt_users |
[] |
Users granted libvirt access (see users) |
libvirt_retries |
2 |
Number of retries for package installation |
libvirt_dnsmasq_management_method |
auto |
DNSMasq management: auto, bind, disable, or none |
libvirt_dnsmasq_interface_types |
[ether] |
Interface types for DNSMasq to listen on (when method is bind) |
| Variable | Default | Description |
|---|---|---|
libvirt_config |
{} |
Per-file directives, as { <file>: { directive: value } }, written to /etc/libvirt/<file>.conf |
Enabling TLS on the daemon (certificates, socket, per-user access, rotation) is covered in the TLS guide, and the firewalld rules in the firewall one.
| Variable | Default | Description |
|---|---|---|
libvirt_pools |
[] |
List of storage pools to create (see pools) |
libvirt_volumes |
[] |
List of storage volumes to create (see volumes) |
libvirt_networks |
[] |
List of virtual networks to create (see networks) |
libvirt_domains |
[] |
List of virtual machines to create (see domains) |
libvirt_default_disk_format |
qcow2 |
Default disk image format for volumes and domains |
libvirt_default_keymap |
en-us |
Default keymap for VNC graphics |
libvirt_default_cpu |
{mode: host-model} |
Default CPU configuration for domains |
libvirt_uri |
qemu:///system |
Default libvirt connection URI |
libvirt_remove_default_network |
false |
Remove libvirt's default network |
libvirt_active_default_network |
{{ not libvirt_remove_default_network }} |
Keep libvirt's default network active |
- TLS — enable TLS, deploy certificates, per-user access, rotation
- Live migration — migrate running domains between hosts
- Firewall — firewalld rules and ports
- Users — grant users libvirt access
- Pools, Volumes, Networks and Domains — provisioning resources
What changed in each release, and what an upgrade asks of your inventory, is in the changelog.
Be sure to have the community.libvirt >= 2.0 installad on your system,
or present in your requirements.yml.
Install and configure libvirt on a node:
- name: Libvirt
hosts: all
roles:
- name: gwerlas.libvirtProvisioning resources, enabling TLS and live-migrating domains are covered in the documentation above.
It's only possible to add physical disk to domain in qemu:///system connection