Skip to content

Commit

Permalink
Extract volume defaults
Browse files Browse the repository at this point in the history
Pull out volume defaults from templates into the defaults file, to
ensure the role is kept DRY.
  • Loading branch information
Will Miller committed Aug 23, 2018
1 parent e91af31 commit 77e0ca4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
# file path is not given.
libvirt_vm_default_console_log_dir: "/var/log/libvirt-consoles/"

# The default format for Libvirt volumes.
libvirt_volume_default_format: qcow2

# The default device for Libvirt volumes.
libvirt_volume_default_device: disk

# Path to cache downloaded images.
libvirt_image_cache_path: "/tmp/"

Expand Down
2 changes: 1 addition & 1 deletion tasks/volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{ item.name }}
{{ item.pool }}
{{ item.capacity }}
{{ item.format | default('qcow2') }}
{{ item.format | default(libvirt_volume_default_format) }}
{% if item.image is defined %}
{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions templates/vm.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<devices>
<emulator>{{ libvirt_vm_emulator }}</emulator>
{% for volume in volumes %}
<disk type='volume' device='{{ volume.device | default('disk') }}'>
<driver name='qemu' type='{{ volume.format }}'/>
<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] }}'/>
</disk>
Expand Down

0 comments on commit 77e0ca4

Please sign in to comment.