Skip to content

Commit

Permalink
Merge pull request #6 from w-miller/direct-interfaces
Browse files Browse the repository at this point in the history
Fix default handling, and other minor changes
  • Loading branch information
markgoddard authored Aug 23, 2018
2 parents c4a8479 + 77e0ca4 commit 3a4a849
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 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
1 change: 1 addition & 0 deletions tasks/autodetect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- name: Detect the QEMU emulator binary path
shell: which qemu-system-{{ libvirt_vm_arch }}
register: qemu_emulator_result
changed_when: false

- name: Set a fact containing the QEMU emulator binary path
set_fact:
Expand Down
7 changes: 5 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
- include_tasks: autodetect.yml
# We need to know the engine and emulator if we're creating any new VMs.
when: libvirt_vms | rejectattr('state', 'eq', 'absent') | list
# We don't need to know the engine and emulator if we're not creating any new
# VMs.
when: >-
(libvirt_vms | selectattr('state', 'defined')
| selectattr('state', 'eq', 'absent') | list) != libvirt_vms
- include_tasks: volumes.yml
vars:
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 3a4a849

Please sign in to comment.