diff --git a/defaults/main.yml b/defaults/main.yml index 909d982..027618d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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/" diff --git a/tasks/autodetect.yml b/tasks/autodetect.yml index 404ef7d..a29647c 100644 --- a/tasks/autodetect.yml +++ b/tasks/autodetect.yml @@ -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: diff --git a/tasks/main.yml b/tasks/main.yml index 772b9a2..88ae3e8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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: diff --git a/tasks/volumes.yml b/tasks/volumes.yml index 1c49872..7422d5b 100644 --- a/tasks/volumes.yml +++ b/tasks/volumes.yml @@ -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 %} diff --git a/templates/vm.xml.j2 b/templates/vm.xml.j2 index 9aed95d..987c147 100644 --- a/templates/vm.xml.j2 +++ b/templates/vm.xml.j2 @@ -19,8 +19,8 @@ {{ libvirt_vm_emulator }} {% for volume in volumes %} - - + +