Skip to content

Commit d7ad6de

Browse files
committed
Add volume block type support
Allows plugging a block device directly into a VM.
1 parent 933b8cb commit d7ad6de

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Role Variables
2727
stored. Default is '/var/lib/libvirt/images'.
2828

2929
- `libvirt_volume_default_type`: What type of backing volume does the instance
30-
use? Default is `volume`. Options include `file`, `network` and `volume`.
30+
use? Default is `volume`. Options include `block`, `file`, `network` and
31+
`volume`.
3132

3233
- `libvirt_volume_default_format`: Format for volumes created by the role.
3334
Default is `qcow2`. Options include `raw`, `qcow2`, `vmdk`. See `man virsh`
@@ -115,6 +116,7 @@ Role Variables
115116
- `backing_image`: (optional) name of the backing volume which is assumed to already be the same pool (copy-on-write).
116117
- `image` and `backing_image` are mutually exclusive options.
117118
- `target`: (optional) Manually influence type and order of volumes
119+
- `dev`: (optional) Block device path when type is `block`.
118120

119121
- `interfaces`: a list of network interfaces to attach to the VM.
120122
Each network interface is defined with the following dict:
@@ -218,6 +220,9 @@ Example Playbook
218220
- 'mon1.example.org'
219221
- 'mon2.example.org'
220222
- 'mon3.example.org'
223+
- type: 'block'
224+
format: 'raw'
225+
dev: '/dev/sda'
221226

222227
interfaces:
223228
- network: 'br-datacentre'

templates/vm.xml.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
{% endfor %}
5454
</source>
5555
{% endif %} {# End volume.source.name check #}
56+
{% elif volume.type | default(libvirt_volume_default_type) == 'block' %}
57+
<source dev='{{ volume.dev }}'/>
5658
{% else %} {# End elif volume.type is defined #}
5759
<source pool='{{ volume.pool }}' volume='{{ volume.name }}'/>
5860
{% endif %}

0 commit comments

Comments
 (0)