stackhpc.libvirt-host
Libvirt Host
This role sets up a host to work as a Libvirt/KVM hypervisor. It can also set up storage pools and networks on that host.
Requirements
The host must have Virtualization Technology (VT) turned on.
Role Variables
libvirt_host_pools
is a list of storage pools to create and activate. Each entry should include:
name
: The pool's name.type
: The pool type, with current options beingdir
,logical
, orrbd
. Note:lvm2
can be used as an old name forlogical
, but it will be removed in the future.capacity
: The storage size in bytes for the pool (optional).path
: The full path to where the pool's directory is located.mode
: The access mode for the pool (only applicable fordir
). Provide as an integer without a leading zero (example:mode: 755
).owner
: The pool's owner (only applicable fordir
).group
: The pool's group (only applicable fordir
).source
: The volume group name if the type islogical
, or the RBD pool name if the type isrbd
.pvs
: A list of physical volumes that make up this volume group (only forlogical
).hosts
: List of IPs or hostnames for Ceph monitors (only forrbd
).username
: The username for RADOS authentication (only forrbd
).passphrase
: The passphrase for RADOS authentication (only forrbd
).
libvirt_host_networks
is a list of networks to set up. Each entry should include:
name
: The network's name.mode
: The network's forwarding mode, options arebridge
,route
,open
, andnat
. Leave it empty for an isolated network.bridge
: The name of the bridge interface.ip
: The IP address for the virtual bridge, needed forroute
,open
, andnat
modes.netmask
: The netmask for the virtual bridge, required forroute
,open
, andnat
modes.domain
: The DNS domain name forroute
,open
, andnat
modes, defaults to the network name (optional).dhcp_start
: The first IP in the DHCP range forroute
,open
, ornat
modes (optional).dhcp_end
: The last IP in the DHCP range forroute
,open
, ornat
modes (optional).routes
: Optional extra routes can be defined, including:address
: The route's address (required).prefix
: The route's prefix (required).gateway
: The route's gateway (required).metric
: The route's metric (optional).
ipv6
: The IPv6 address for the virtual bridge (optional).ipv6_prefix
: The IPv6 prefix for the virtual bridge (optional).routesv6
: Optional extra IPv6 routes defined as before.
libvirt_host_require_vt
: Indicates if Intel Virtualization Technology (VT) must be enabled to run this role. Although it enhances VM performance, it may not be available in some setups. Default is true
.
libvirt_host_qemu_emulators
: Specifies the architectures for which to install QEMU system emulators, e.g., x86
. If libvirt_host_require_vt
is false
, the default value is ['x86']
, otherwise, it is an empty list.
libvirt_host_enable_efi_support
: Indicates whether to enable EFI support, defaults to false
due to the need for additional packages.
libvirt_host_var_prefix
: Sets the directory in /var/run
that libvirt uses for state storage, e.g., Unix domain sockets, and the default PID file name. Override if there is a naming conflict, defaults to ""
.
libvirt_host_socket_dir
: Location where the libvirtd socket is created. Defaults to /var/run/{{ libvirt_host_var_prefix }}
if libvirt_host_var_prefix
is set, otherwise ""
.
libvirt_host_pid_path
: Path to the PID file to prevent multiple daemon instances. Defaults to /var/run/{{ libvirt_host_var_prefix }}.pid
if libvirt_host_var_prefix
is set, otherwise ""
.
libvirt_host_libvirtd_args
: Command-line options passed to libvirtd when it starts—quotes will be added automatically.
libvirt_host_uri
: The connection URI for libvirt. Defaults to qemu+unix:///system?socket={{ libvirt_host_socket_dir }}/libvirt-sock
if libvirt_host_var_prefix
is set, otherwise ""
. If set to a false value, no specific connection URI will be used in virsh or any virt_ Ansible modules.
libvirt_host_python3
: Specifies if the Python 3 version of the libvirt bindings should be installed. If false
, the Python 2 bindings will be installed.
libvirt_host_install_daemon
: Indicates if the libvirt daemon should be installed and activated. Default is true
.
libvirt_host_install_client
: Indicates if the libvirt client should be installed and activated. Default is true
.
libvirt_host_extra_daemon_packages
: List of extra packages to install on libvirt daemon hosts.
libvirt_host_extra_client_packages
: List of extra packages to install on libvirt client hosts.
libvirt_host_libvirtd_conf_enabled
: Indicates if libvirtd.conf
should be set up. Default is true
.
libvirt_host_libvirtd_conf
: Configuration settings for libvirtd.conf
. A dictionary mapping option names to values. Default is empty.
libvirt_host_qemu_conf_enabled
: Indicates if qemu.conf
should be set up. Default is true
.
libvirt_host_qemu_conf
: Configuration settings for qemu.conf
. A dictionary mapping option names to values. Default is empty.
libvirt_host_enable_sasl_support
: Determines if SASL authentication support should be enabled. Default is false
.
libvirt_host_sasl_conf_enabled
: Indicates if SASL authentication should be configured (/etc/sasl2/libvirt.conf
). Default matches libvirt_host_enable_sasl_support
.
libvirt_host_sasl_conf
: Configuration settings for SASL (/etc/sasl2/libvirt.conf
). A string.
libvirt_host_sasl_mech_list
: List of enabled libvirt SASL authentication methods. Default is ["SCRAM-SHA-256"]
when libvirt_host_tls_listen
is true
, otherwise ["DIGEST-MD5"]
.
libvirt_host_sasl_credentials
: List of SASL authentication credentials to create, with each item being a dict containing username
and password
. Default is a list with a single item containing libvirt_host_sasl_authname
and libvirt_host_sasl_password
.
libvirt_host_sasl_authname
: The username for SASL authentication. Default is libvirt
.
libvirt_host_sasl_password
: The password for SASL authentication. Default is unset.
libvirt_host_sasl_auth_conf_enabled
: Indicates if SASL authentication credentials should be configured (/etc/libvirt/auth.conf
). Default matches libvirt_host_enable_sasl_support
.
libvirt_host_sasl_auth_conf
: Configuration settings for SASL authentication credentials (/etc/libvirt/auth.conf
). A string.
libvirt_host_sasl_auth_conf_filename
: Name of the file to save SASL authentication credentials. Default is "/etc/libvirt/auth.conf"
.
libvirt_host_sasl_auth_conf_owner
: Owner of the file for SASL credentials. Default is "root"
.
libvirt_host_sasl_auth_conf_group
: Group for the file for SASL credentials. Default is "root"
.
libvirt_host_sasl_auth_conf_mode
: Permissions for the file for SASL credentials. Default is "0600"
.
libvirt_host_tcp_listen
: Indicates if the TCP socket unit should be enabled via systemd. Default is false
.
libvirt_host_tcp_listen_address
: TCP socket ListenStream address. See man systemd.socket
for format. Default is unset.
libvirt_host_tls_listen
: Indicates if the TLS socket unit should be enabled via systemd. Default is false
.
libvirt_host_tls_listen_address
: TLS socket ListenStream address. See man systemd.socket
for format. Default is unset.
libvirt_host_tls_server_cert
: TLS server certificate. Default is unset.
libvirt_host_tls_server_key
: TLS server key. Default is unset.
libvirt_host_tls_client_cert
: TLS client certificate. Default is unset.
libvirt_host_tls_client_key
: TLS client key. Default is unset.
libvirt_host_tls_cacert
: TLS CA certificate. Default is unset.
libvirt_host_configure_apparmor
: Indicates if AppArmor should be set up for directory storage pools.
Dependencies
None
Example Playbook
---
- name: Ensure that Libvirt is configured
hosts: all
roles:
- role: stackhpc.libvirt-host
libvirt_host_pools:
- name: my-pool
type: dir
capacity: 1024
path: /path/to/pool
mode: 755
owner: my-user
group: my-group
- name: lvm_pool
type: logical
source: vg1
target: /dev/vg1
pvs:
- /dev/sda3
- name: rbd-pool
type: rbd
source: rbd
hosts:
- 192.168.42.200
- 192.168.42.204
- 192.168.42.208
username: admin
passphrase: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
libvirt_host_networks:
- name: br-example
mode: bridge
bridge: br-example
- name: brnat-example
mode: nat
bridge: brnat-example
domain: example.local
ip: 192.168.133.254
netmask: 255.255.255.0
dhcp_start: 192.168.133.100
dhcp_end: 192.168.133.200
Author Information
- Mark Goddard (mark@stackhpc.com)
Role to install and configure a host as a Libvirt/KVM hypervisor
ansible-galaxy install stackhpc.libvirt-host