Skip to content

Commit 3a4a849

Browse files
authored
Merge pull request #6 from w-miller/direct-interfaces
Fix default handling, and other minor changes
2 parents c4a8479 + 77e0ca4 commit 3a4a849

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
# file path is not given.
55
libvirt_vm_default_console_log_dir: "/var/log/libvirt-consoles/"
66

7+
# The default format for Libvirt volumes.
8+
libvirt_volume_default_format: qcow2
9+
10+
# The default device for Libvirt volumes.
11+
libvirt_volume_default_device: disk
12+
713
# Path to cache downloaded images.
814
libvirt_image_cache_path: "/tmp/"
915

tasks/autodetect.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- name: Detect the QEMU emulator binary path
4141
shell: which qemu-system-{{ libvirt_vm_arch }}
4242
register: qemu_emulator_result
43+
changed_when: false
4344

4445
- name: Set a fact containing the QEMU emulator binary path
4546
set_fact:

tasks/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
22
- include_tasks: autodetect.yml
3-
# We need to know the engine and emulator if we're creating any new VMs.
4-
when: libvirt_vms | rejectattr('state', 'eq', 'absent') | list
3+
# We don't need to know the engine and emulator if we're not creating any new
4+
# VMs.
5+
when: >-
6+
(libvirt_vms | selectattr('state', 'defined')
7+
| selectattr('state', 'eq', 'absent') | list) != libvirt_vms
58
69
- include_tasks: volumes.yml
710
vars:

tasks/volumes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{{ item.name }}
2020
{{ item.pool }}
2121
{{ item.capacity }}
22-
{{ item.format | default('qcow2') }}
22+
{{ item.format | default(libvirt_volume_default_format) }}
2323
{% if item.image is defined %}
2424
{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}
2525
{% endif %}

templates/vm.xml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<devices>
2020
<emulator>{{ libvirt_vm_emulator }}</emulator>
2121
{% for volume in volumes %}
22-
<disk type='volume' device='{{ volume.device | default('disk') }}'>
23-
<driver name='qemu' type='{{ volume.format }}'/>
22+
<disk type='volume' device='{{ volume.device | default(libvirt_volume_default_device) }}'>
23+
<driver name='qemu' type='{{ volume.format | default(libvirt_volume_default_format) }}'/>
2424
<source pool='{{ volume.pool }}' volume='{{ volume.name }}'/>
2525
<target dev='vd{{ 'abcdefghijklmnopqrstuvwxyz'[loop.index] }}'/>
2626
</disk>

0 commit comments

Comments
 (0)