airshipctl/roles/libvirt-domain/defaults/main.yaml
Alexander Noskov 1fcb6df061 Enable UEFI in addition to legacy bootmode
In order to enable UEFI support we need to configure guests VM to use OVMF
(Open Virtual Machine Firmware)

Closes: #319

Change-Id: I4b1c3b9fa8f1f0fe42ced7ec3e57b9d95dd4a3f5
2020-08-13 13:14:37 -05:00

194 lines
7.1 KiB
YAML

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
# The default directory in which to store VM console logs, if a VM-specific log
# file path is not given.
libvirt_vm_default_console_log_dir: "/var/log/libvirt-consoles"
# The default location for libvirt images
libvirt_volume_default_images_path: '/var/lib/libvirt/images'
# Default type for Libvirt volumes
libvirt_volume_default_type: volume
# The default format for Libvirt volumes.
libvirt_volume_default_format: qcow2
# The default device for Libvirt volumes.
libvirt_volume_default_device: disk
# CPU architecture.
libvirt_vm_arch: x86_64
# Virtualisation engine. If not set, the role will attempt to auto-detect the
# optimal engine to use.
libvirt_vm_engine:
# Path to emulator binary. If not set, the role will attempt to auto-detect the
# correct emulator to use.
libvirt_vm_emulator:
# Default value for clock syncing. The default (false) uses <clock sync="localtime">
# to configure the instances clock synchronisation. Change to a timezone to make
# configuration use <clock offset="specified offset">
libvirt_vm_clock_offset: False
# A list of specifications of VMs to be created.
# For backwards compatibility, libvirt_vms defaults to a singleton list using
# the values of the deprecated variables below.
# See README.md or tasks/main.yaml for these attributes' defaults.
libvirt_domain:
# State of the VM. May be 'present' or 'absent'.
state: "{{ libvirt_vm_state }}"
# Name of the VM.
name: "{{ libvirt_vm_name }}"
# Memory in MB.
memory_mb: "{{ libvirt_vm_memory_mb }}"
# Number of vCPUs.
vcpus: "{{ libvirt_vm_vcpus }}"
# Virtual machine type.
machine: "{{ libvirt_vm_machine }}"
# Virtual machine CPU mode.
cpu_mode: "{{ libvirt_vm_cpu_mode | default(libvirt_cpu_mode_default, true) }}"
# List of volumes.
volumes: "{{ libvirt_vm_volumes }}"
# What time should the clock be synced to on boot (utc/localtime/timezone/variable)
clock_offset: "localtime"
# List of network interfaces.
interfaces: "{{ libvirt_vm_interfaces }}"
# Path to console log file.
console_log_path: "{{ libvirt_vm_console_log_path }}"
# XML template file to source domain definition
xml_file: vm.xml.j2
# Variables to add to the enviroment that is used to execute virsh commands
libvirt_vm_virsh_default_env: "{{ { 'LIBVIRT_DEFAULT_URI': libvirt_vm_uri } if libvirt_vm_uri else {} }}"
# Override for the libvirt connection uri. Leave unset to use the default.
libvirt_vm_uri: ""
# Default CPU mode if libvirt_vm_cpu_mode or vm.cpu_mode is undefined
libvirt_cpu_mode_default: "{{ 'host-passthrough' if libvirt_vm_engine == 'kvm' else 'host-model' }}"
libvirt_domain_template_default: |
<domain type='{{ libvirt_vm_engine }}'>
<name>{{ libvirt_domain.name }}</name>
<memory>{{ libvirt_domain.memory_mb | int * 1024 }}</memory>
<vcpu>{{ libvirt_domain.vcpus }}</vcpu>
{% if libvirt_domain.clock_offset |default( libvirt_vm_clock_offset ) %}
<clock offset="{{ libvirt_domain.clock_offset }}"/>
{% else %}
<clock sync="localtime"/>
{% endif %}
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<os>
<type arch='{{ libvirt_vm_arch }}'{% if machine is not none %} machine='{{ machine }}'{% endif %}>hvm</type>
{% if libvirt_domain.boot_mode is defined and libvirt_domain.boot_mode == 'UEFI' %}
<loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
{% endif %}
<bootmenu enable='no'/>
<boot dev='hd'/>
<boot dev='cdrom'/>
<boot dev='network'/>
<bios useserial='yes'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
{% if cpu_mode %}
<cpu mode='{{ cpu_mode }}'>
<model fallback='allow'/>
</cpu>
{% endif %}
<devices>
<emulator>{{ libvirt_vm_emulator }}</emulator>
{% for volume in volumes %}
<disk type='{{ volume.type | default(libvirt_volume_default_type) }}' device='{{ volume.device | default(libvirt_volume_default_device) }}'>
<driver name='qemu' type='{{ volume.format | default(libvirt_volume_default_format) }}'/>
{% if volume.type | default(libvirt_volume_default_type) == 'file' %}
<source file='{{ volume.file_path |default(libvirt_volume_default_images_path) }}/{{ volume.name}}'/>
{% else %}
<source pool='{{ volume.pool }}' volume='{{ volume.name }}'/>
{% endif %}
{% if volume.target is undefined %}
<target dev='vd{{ 'abcdefghijklmnopqrstuvwxyz'[loop.index - 1] }}'/>
{% else %}
<target dev='{{ volume.target }}' bus='{{ volume.bus if volume.bus is defined else 'virtio' }}'/>
{% endif %}
</disk>
{% endfor %}
{% for controller in controllers | default([]) %}
<controller type='{{ controller }}'>
<address type='pci'/>
</controller>
{% endfor %}
{% for interface in interfaces %}
{% if interface.type is defined and interface.type == 'direct' %}
<interface type='direct'>
<source dev='{{ interface.source.dev }}' mode='{{ interface.source.mode | default('vepa') }}'/>
{% elif interface.type is defined and interface.type == 'bridge' %}
<interface type='bridge'>
<source bridge='{{ interface.source.dev }}'/>
{% elif interface.type is not defined or interface.type == 'network' %}
<interface type='network'>
<source network='{{ interface.network }}'/>
{% endif %}
{% if interface.mac | default("") != "" %}
<mac address='{{ interface.mac }}'/>
{% endif %}
{# if the network configuration is invalid this can still appear in the xml #}
{# (say you enter 'bond' instead of 'bridge' in your variables) #}
<model type='virtio'/>
</interface>
{% endfor %}
{% if console_log_enabled | bool %}
<serial type='file'>
<source path='{{ console_log_path }}'/>
</serial>
<serial type='pty'/>
<console type='file'>
<source path='{{ console_log_path }}'/>
<target type='serial'/>
</console>
{% else %}
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
{% endif %}
{% if enable_vnc |bool %}
<graphics type='vnc' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
{% endif %}
<rng model="virtio"><backend model="random">/dev/urandom</backend></rng>
</devices>
</domain>