File tree Expand file tree Collapse file tree 5 files changed +79
-2
lines changed Expand file tree Collapse file tree 5 files changed +79
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,14 @@ Defaults to `present`.
21
21
22
22
` libvirt_vm_vcpus ` : the number of VCPU cores to assign to the VM.
23
23
24
+ ` libvirt_vm_engine ` : virtualisation engine. If not set, the role will attempt
25
+ to auto-detect the optimal engine to use.
26
+
27
+ ` libvirt_vm_emulator ` : path to emulator binary. If not set, the role will
28
+ attempt to auto-detect the correct emulator to use.
29
+
30
+ ` libvirt_vm_arch ` : CPU architecture, default is ` x86_64 ` .
31
+
24
32
` libvirt_vm_volumes ` : a list of volumes to attach to the VM. Each volume is
25
33
defined with the following dict:
26
34
- ` name ` : Name to associate with the volume being created.
Original file line number Diff line number Diff line change @@ -11,6 +11,17 @@ libvirt_vm_memory_mb:
11
11
# Number of vCPUs.
12
12
libvirt_vm_vcpus :
13
13
14
+ # Virtualisation engine. If not set, the role will attempt to auto-detect the
15
+ # optimal engine to use.
16
+ libvirt_vm_engine :
17
+
18
+ # Path to emulator binary. If not set, the role will attempt to auto-detect the
19
+ # correct emulator to use.
20
+ libvirt_vm_emulator :
21
+
22
+ # CPU architecture.
23
+ libvirt_vm_arch : x86_64
24
+
14
25
# List of volumes.
15
26
libvirt_vm_volumes : []
16
27
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Detect the virtualisation engine
3
+ block :
4
+ - name : Load the kvm kernel module
5
+ modprobe :
6
+ name : kvm
7
+ become : true
8
+ failed_when : false
9
+
10
+ - name : Check for the KVM device
11
+ stat :
12
+ path : /dev/kvm
13
+ register : stat_kvm
14
+
15
+ - name : Set a fact containing the virtualisation engine
16
+ set_fact :
17
+ libvirt_vm_engine : " {% if stat_kvm.stat.exists %}kvm{% else %}qemu{% endif %}"
18
+ when : libvirt_vm_engine is none
19
+
20
+ - name : Detect the virtualisation emulator
21
+ block :
22
+ - block :
23
+ - name : Detect the KVM emulator binary path
24
+ stat :
25
+ path : " {{ item }}"
26
+ register : kvm_emulator_result
27
+ with_items :
28
+ - /usr/bin/kvm
29
+ - /usr/bin/qemu-kvm
30
+ - /usr/libexec/qemu-kvm
31
+
32
+ - name : Set a fact containing the KVM emulator binary path
33
+ set_fact :
34
+ libvirt_vm_emulator : " {{ item.item }}"
35
+ with_items : " {{ kvm_emulator_result.results }}"
36
+ when : item.stat.exists
37
+ when : libvirt_vm_engine == 'kvm'
38
+
39
+ - block :
40
+ - name : Detect the QEMU emulator binary path
41
+ shell : which qemu-system-{{ libvirt_vm_arch }}
42
+ register : qemu_emulator_result
43
+
44
+ - name : Set a fact containing the QEMU emulator binary path
45
+ set_fact :
46
+ libvirt_vm_emulator : " {{ qemu_emulator_result.stdout }}"
47
+ when : libvirt_vm_engine == 'qemu'
48
+
49
+ - name : Fail if unable to detect the emulator
50
+ fail :
51
+ msg : Unable to detect emulator for engine {{ libvirt_vm_engine }}.
52
+ when : libvirt_vm_emulator is none
53
+ when : libvirt_vm_emulator is none
Original file line number Diff line number Diff line change 1
1
---
2
2
- block :
3
+ - include : autodetect.yml
3
4
- include : volumes.yml
4
5
- include : vm.yml
5
6
when : libvirt_vm_state == 'present'
Original file line number Diff line number Diff line change 1
- <domain type =' kvm ' >
1
+ <domain type =' {{ libvirt_vm_engine }} ' >
2
2
<name >{{ libvirt_vm_name }}</name >
3
3
<memory >{{ libvirt_vm_memory_mb | int * 1024 }}</memory >
4
4
<vcpu >{{ libvirt_vm_vcpus }}</vcpu >
5
5
<clock sync =" localtime" />
6
6
<os >
7
- <type arch =' x86_64 ' >hvm</type >
7
+ <type arch =' {{ libvirt_vm_arch }} ' >hvm</type >
8
8
</os >
9
+ {% if libvirt_vm_engine == 'kvm' %}
10
+ <cpu mode =' host-passthrough' />
11
+ {% endif %}
9
12
<devices >
13
+ <emulator >{{ libvirt_vm_emulator }}</emulator >
10
14
{% for volume in libvirt_vm_volumes %}
11
15
<disk type =' volume' device =' {{ volume.device | default(' disk ' ) }}' >
12
16
<driver name =' qemu' type =' {{ volume.format }}' />
You can’t perform that action at this time.
0 commit comments