Closed JPvRiel closed 5 years ago
FYI, this is how el7_vm_xml.j2
looked:
<domain type='{{ libvirt_vm_engine }}'>
<name>{{ vm.name }}</name>
<description>Custom xml template for RHEL or CentOS 7 guest</description>
<memory>{{ vm.memory_mb | int * 1024 }}</memory>
<vcpu>{{ vm.vcpus }}</vcpu>
<os>
<type arch='{{ libvirt_vm_arch }}'{% if machine is not none %} machine='{{ machine }}'{% endif %}>hvm</type>
<bootmenu enable='no'/>
<boot dev='hd'/>
<bios useserial='yes'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu{% if cpu_mode is not none %} mode='{{ cpu_mode }}'{% endif %}>
<model fallback='allow'/>
</cpu>
<clock offset='utc'>
<timer name="kvmclock" present="yes"/>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>{{ libvirt_vm_emulator }}</emulator>
{% for volume in volumes %}
<disk type='volume' device='{{ volume.device | default(libvirt_volume_default_device) }}'>
<driver name='qemu' type='{{ volume.format | default(libvirt_volume_default_format) }}'/>
<source pool='{{ volume.pool }}' volume='{{ volume.name }}'/>
<target dev='vd{{ 'abcdefghijklmnopqrstuvwxyz'[loop.index - 1] }}'/>
</disk>
{% 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') }}'/>
{% else %}
<interface type='network'>
<source network='{{ interface.network }}'/>
{% endif %}
<model type='virtio'/>
</interface>
{% endfor %}
<!-- support qemu guest agent -->
<controller type='virtio-serial' index='0'>
<alias name='virtio-serial0'/>
</controller>
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
<address type='virtio-serial' controller='0'/>
</channel>
{% 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 %}
</devices>
</domain>
As per commit comments.
I found it a bit awkward trying to supply / set
vm.xml.j2
as a default indefaults/main.yml
. When the role runs, if the calling play doesn't setxml_file
, the role appears to havevm.xml_file
undefined and the value indefaults/main.yml
doesn't have any effect - so duplicating it there is for cosmetic/documentation value. Couldn't think of a cleaner way about it given the defaults are a singleton and omitted parts don't seem to set defaults.Tested both setting xml_file and not setting xml_file as working while my custom file
el7_vm.xml.j2
was in the playbook dir/templates
location.E.g.