11Libvirt VM
22==========
33
4- This role configures an creates (or destroys) a VM on a KVM hypervisor.
4+ This role configures and creates (or destroys) VMs on a KVM hypervisor.
55
66Requirements
77------------
@@ -12,45 +12,70 @@ be preconfigured with libvirt/KVM.
1212Role Variables
1313--------------
1414
15- ` libvirt_vm_state ` : set to ` present ` to create or ` absent ` to destroy the VM.
16- Defaults to ` present ` .
15+ - ` libvirt_vm_default_console_log_dir ` : The default directory in which to store
16+ VM console logs, if a VM-specific log file path is not given. Default is
17+ "/var/log/libvirt/qemu/".
1718
18- ` libvirt_vm_name ` : the name to assign to the VM.
19+ - ` libvirt_image_cache_path ` : The directory in which to cache downloaded
20+ images. Default is "/tmp/".
1921
20- ` libvirt_vm_memory_mb ` : the memory to assign to the VM, in megabytes.
22+ - ` libvirt_vm_engine ` : virtualisation engine. If not set, the role will attempt
23+ to auto-detect the optimal engine to use.
2124
22- ` libvirt_vm_vcpus ` : the number of VCPU cores to assign to the VM.
25+ - ` libvirt_vm_emulator ` : path to emulator binary. If not set, the role will
26+ attempt to auto-detect the correct emulator to use.
2327
24- ` libvirt_vm_engine ` : virtualisation engine. If not set, the role will attempt
25- to auto-detect the optimal engine to use.
28+ - ` libvirt_vm_arch ` : CPU architecture, default is ` x86_64 ` .
2629
27- ` libvirt_vm_emulator ` : path to emulator binary. If not set, the role will
28- attempt to auto-detect the correct emulator to use.
30+ - ` libvirt_vms ` : list of VMs to be created/destroyed. Each one may have the
31+ following attributes:
2932
30- ` libvirt_vm_arch ` : CPU architecture, default is ` x86_64 ` .
33+ - ` state ` : set to ` present ` to create or ` absent ` to destroy the VM.
34+ Defaults to ` present ` .
3135
32- ` libvirt_vm_machine ` : Virtual machine type. Default is ` None ` if
33- ` libvirt_vm_engine ` is ` kvm ` , otherwise ` pc-1.0 ` .
36+ - ` name ` : the name to assign to the VM.
3437
35- ` libvirt_vm_cpu_mode ` : Virtual machine CPU mode. Default is ` host-passthrough `
36- if ` libvirt_vm_engine ` is ` kvm ` , otherwise ` host-model ` .
38+ - ` memory_mb ` : the memory to assign to the VM, in megabytes.
3739
38- ` libvirt_vm_volumes ` : a list of volumes to attach to the VM. Each volume is
39- defined with the following dict:
40- - ` name ` : Name to associate with the volume being created.
41- - ` device ` : ` disk `
42- - ` format ` : options include ` raw ` , ` qcow2 ` , ` vmdk ` . See ` man virsh ` for the
43- full range. Default is ` qcow2 `
44- - ` capacity ` : volume capacity (can be suffixed with M,G,T or MB,GB,TB, etc)
45- - ` image ` : (optional) a URL to an image with which the volume is initalised.
46- - ` pool ` : Name or UUID of the storage pool from which the volume should be
47- allocated.
40+ - ` vcpus ` : the number of VCPU cores to assign to the VM.
4841
49- ` libvirt_vm_interfaces ` : a list of network interfaces to attach to the VM.
50- Each network interface is defined with the following dict:
51- - ` network ` : Name of the network to which an interface should be attached.
42+ - ` machine ` : Virtual machine type. Default is ` None ` if
43+ ` libvirt_vm_engine ` is ` kvm ` , otherwise ` pc-1.0 ` .
5244
53- ` libvirt_vm_image_cache_path ` : path to cache downloaded images.
45+ - ` cpu_mode ` : Virtual machine CPU mode. Default is ` host-passthrough ` if
46+ ` libvirt_vm_engine ` is ` kvm ` , otherwise ` host-model ` .
47+
48+ - ` volumes ` : a list of volumes to attach to the VM. Each volume is
49+ defined with the following dict:
50+ - ` name ` : Name to associate with the volume being created.
51+ - ` device ` : ` disk `
52+ - ` format ` : options include ` raw ` , ` qcow2 ` , ` vmdk ` . See ` man virsh ` for the
53+ full range. Default is ` qcow2 `
54+ - ` capacity ` : volume capacity (can be suffixed with M,G,T or MB,GB,TB, etc)
55+ - ` image ` : (optional) a URL to an image with which the volume is initalised.
56+ - ` pool ` : Name or UUID of the storage pool from which the volume should be
57+ allocated.
58+
59+ - ` interfaces ` : a list of network interfaces to attach to the VM.
60+ Each network interface is defined with the following dict:
61+ - ` network ` : Name of the network to which an interface should be attached.
62+
63+ - ` console_log_enabled ` : if ` true ` , log console output to a file at the
64+ path specified by ` console_log_path ` , ** instead of** to a PTY. If
65+ ` false ` , direct terminal output to a PTY at serial port 0. Default is
66+ ` false ` .
67+
68+ - ` console_log_path ` : Path to console log file. Default is
69+ ` {{ libvirt_vm_default_console_log_dir }}/{{ name }}-console.log ` .
70+
71+
72+ N.B. the following variables are deprecated: ` libvirt_vm_state ` ,
73+ ` libvirt_vm_name ` , ` libvirt_vm_memory_mb ` , ` libvirt_vm_vcpus ` ,
74+ ` libvirt_vm_engine ` , ` libvirt_vm_machine ` , ` libvirt_vm_cpu_mode ` ,
75+ ` libvirt_vm_volumes ` , ` libvirt_vm_interfaces ` and
76+ ` libvirt_vm_console_log_path ` . If the variable ` libvirt_vms ` is left unset, its
77+ default value will be a singleton list containing a VM specification using
78+ these deprecated variables.
5479
5580Dependencies
5681------------
@@ -61,22 +86,37 @@ Example Playbook
6186----------------
6287
6388 ---
64- - name: Create a VM
89+ - name: Create VMs
6590 hosts: hypervisor
6691 roles:
6792 - role: stackhpc.libvirt-vm
68- libvirt_vm_state: present
69- libvirt_vm_name: 'my-vm'
70- libvirt_vm_memory_mb: 512
71- libvirt_vm_vcpus: 2
72- libvirt_vm_volumes:
73- - name: 'data'
74- device: 'disk'
75- format: 'qcow2'
76- capacity: '400GB'
77- pool: 'my-pool'
78- libvirt_vm_interfaces:
79- - network: 'br-datacentre'
93+ libvirt_vms:
94+ - state: present
95+ name: 'vm1'
96+ memory_mb: 512
97+ vcpus: 2
98+ volumes:
99+ - name: 'data1'
100+ device: 'disk'
101+ format: 'qcow2'
102+ capacity: '400GB'
103+ pool: 'my-pool'
104+ interfaces:
105+ - network: 'br-datacentre'
106+
107+ - state: present
108+ name: 'vm2'
109+ memory_mb: 1024
110+ vcpus: 1
111+ volumes:
112+ - name: 'data2'
113+ device: 'disk'
114+ format: 'qcow2'
115+ capacity: '200GB'
116+ pool: 'my-pool'
117+ interfaces:
118+ - network: 'br-datacentre'
119+
80120
81121Author Information
82122------------------
0 commit comments