Skip to content

Commit 77e0ca4

Browse files
author
Will Miller
committed
Extract volume defaults
Pull out volume defaults from templates into the defaults file, to ensure the role is kept DRY.
1 parent e91af31 commit 77e0ca4

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
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/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)