Skip to content

Commit 8d39607

Browse files
authored
Merge branch 'master' into boot_cdrom
2 parents 851e2a5 + e999b7a commit 8d39607

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ Role Variables
1919
- `libvirt_vm_image_cache_path`: The directory in which to cache downloaded
2020
images. Default is "/tmp/".
2121

22+
- `libvirt_volume_default_images_path`: Directory in which instance images are
23+
stored. Default is '/var/lib/libvirt/images'.
24+
25+
- `libvirt_volume_default_type`: What type of backing volume does the instance use? Default is `volume`.
26+
27+
- `libvirt_volume_default_format`: Format for volumes created by the role, Default is `qcow2`.
28+
29+
- `libvirt_volume_default_device`: Control how device appears in guest OS. Defaults to `disk`.
30+
31+
2232
- `libvirt_vm_engine`: virtualisation engine. If not set, the role will attempt
2333
to auto-detect the optimal engine to use.
2434

@@ -36,6 +46,9 @@ Role Variables
3646
- `libvirt_vm_virsh_default_env`: Variables contained within this dictionary are
3747
added to the environment used when executing virsh commands.
3848

49+
- `libvirt_vm_clock_offset`. If defined the instances clock offset is set to
50+
the provided value. When undefined sync is set to `localtime`.
51+
3952
- `libvirt_vms`: list of VMs to be created/destroyed. Each one may have the
4053
following attributes:
4154

@@ -55,11 +68,17 @@ Role Variables
5568
`libvirt_vm_engine` is `kvm`, otherwise `host-model`. Can be set to none
5669
to not configure a cpu mode.
5770

71+
- `clock_offset`: Overrides default set in `libvirt_vm_clock_offset`
72+
73+
- `enable_vnc`: If true enables VNC listening on localhost for use with
74+
VirtManager and similar tools
75+
5876
- `volumes`: a list of volumes to attach to the VM. Each volume is
5977
defined with the following dict:
6078
- `pool`: Name or UUID of the storage pool from which the volume should be
6179
allocated.
62-
- `name`: Name to associate with the volume being created.
80+
- `name`: Name to associate with the volume being created; For `file` type volumes include extension if you would like volumes created with one.
81+
- `file_path`: Where the image of `file` type volumes should be placed; defaults to `libvirt_volume_default_images_path`
6382
- `device`: `disk` or `cdrom`
6483
- `capacity`: volume capacity (can be suffixed with M,G,T or MB,GB,TB, etc) (required when type is `disk`)
6584
- `format`: options include `raw`, `qcow2`, `vmdk`. See `man virsh` for the
@@ -80,6 +99,7 @@ Role Variables
8099
- `network`: Name of the network to which an interface should be
81100
attached. Must be specified if and only if the interface `type` is
82101
`network`.
102+
- `mac`: "Hardware" address of the virtual instance, if absent one is created
83103
- `source`: A dict defining the host interface to which this
84104
VM interface should be attached. Must be specified if and only if the
85105
interface `type` is `direct`. Includes the following attributes:
@@ -154,8 +174,18 @@ Example Playbook
154174
format: 'qcow2'
155175
capacity: '200GB'
156176
pool: 'my-pool'
177+
- name: 'filestore'
178+
type: 'file'
179+
file_path: '/srv/cloud/images'
180+
capacity: '900GB'
157181
interfaces:
158-
- network: 'br-datacentre'
182+
- type: 'direct'
183+
source:
184+
dev: 'eth123'
185+
mode: 'private'
186+
- type: 'bridge'
187+
source:
188+
dev: 'br-datacentre'
159189

160190

161191
Author Information

defaults/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
# file path is not given.
55
libvirt_vm_default_console_log_dir: "/var/log/libvirt-consoles/"
66

7+
# The default location for libvirt images
8+
libvirt_volume_default_images_path: '/var/lib/libvirt/images'
9+
10+
# Default type for Libvirt volumes
11+
libvirt_volume_default_type: volume
12+
713
# The default format for Libvirt volumes.
814
libvirt_volume_default_format: qcow2
915

@@ -29,6 +35,11 @@ libvirt_vm_engine:
2935
# correct emulator to use.
3036
libvirt_vm_emulator:
3137

38+
# Default value for clock syncing. The default (false) uses <clock sync="localtime">
39+
# to configure the instances clock synchronisation. Change to a timezone to make
40+
# configuration use <clock offset="specified offset">
41+
libvirt_vm_clock_offset: False
42+
3243
# A list of specifications of VMs to be created.
3344
# For backwards compatibility, libvirt_vms defaults to a singleton list using
3445
# the values of the deprecated variables below.
@@ -55,6 +66,9 @@ libvirt_vms:
5566
# List of volumes.
5667
volumes: "{{ libvirt_vm_volumes }}"
5768

69+
# What time should the clock be synced to on boot (utc/localtime/timezone/variable)
70+
clock_offset: "localtime"
71+
5872
# List of network interfaces.
5973
interfaces: "{{ libvirt_vm_interfaces }}"
6074

tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
interfaces: "{{ vm.interfaces | default([], true) }}"
3737
start: "{{ vm.start | default(true) }}"
3838
autostart: "{{ vm.autostart | default(true) }}"
39+
enable_vnc: "{{ vm.enable_vnc | default(false) }}"
3940
with_items: "{{ libvirt_vms }}"
4041
loop_control:
4142
loop_var: vm

tasks/volumes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
script: >
1818
virt_volume.sh
1919
-n {{ item.name }}
20-
-p {{ item.pool }}
20+
-p {{ item.pool |default('default') }}
2121
-c {{ item.capacity }}
2222
-f {{ item.format | default(libvirt_volume_default_format) }}
2323
{% if item.image is defined %}

templates/vm.xml.j2

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
<name>{{ vm.name }}</name>
33
<memory>{{ vm.memory_mb | int * 1024 }}</memory>
44
<vcpu>{{ vm.vcpus }}</vcpu>
5+
{% if vm.clock_offset |default( libvirt_vm_clock_offset ) %}
6+
<clock offset="{{ vm.clock_offset }}"/>
7+
{% else %}
58
<clock sync="localtime"/>
9+
{% endif %}
610
<on_poweroff>destroy</on_poweroff>
711
<on_reboot>restart</on_reboot>
812
<on_crash>destroy</on_crash>
@@ -14,6 +18,11 @@
1418
<boot dev='network'/>
1519
<bios useserial='yes'/>
1620
</os>
21+
<features>
22+
<acpi/>
23+
<apic/>
24+
<pae/>
25+
</features>
1726
{% if cpu_mode %}
1827
<cpu mode='{{ cpu_mode }}'>
1928
<model fallback='allow'/>
@@ -22,20 +31,32 @@
2231
<devices>
2332
<emulator>{{ libvirt_vm_emulator }}</emulator>
2433
{% for volume in volumes %}
25-
<disk type='volume' device='{{ volume.device | default(libvirt_volume_default_device) }}'>
34+
<disk type='{{ volume.type | default(libvirt_volume_default_type) }}' device='{{ volume.device | default(libvirt_volume_default_device) }}'>
2635
<driver name='qemu' type='{{ volume.format | default(libvirt_volume_default_format) }}'/>
36+
{% if volume.type | default(libvirt_volume_default_type) == 'file' %}
37+
<source file='{{ volume.file_path |default(libvirt_volume_default_images_path) }}/{{ volume.name}}'/>
38+
{% else %}
2739
<source pool='{{ volume.pool }}' volume='{{ volume.name }}'/>
40+
{% endif %}
2841
<target dev='vd{{ 'abcdefghijklmnopqrstuvwxyz'[loop.index - 1] }}'/>
2942
</disk>
3043
{% endfor %}
3144
{% for interface in interfaces %}
3245
{% if interface.type is defined and interface.type == 'direct' %}
3346
<interface type='direct'>
3447
<source dev='{{ interface.source.dev }}' mode='{{ interface.source.mode | default('vepa') }}'/>
35-
{% else %}
48+
{% elif interface.type is defined and interface.type == 'bridge' %}
49+
<interface type='bridge'>
50+
<source bridge='{{ interface.source.dev }}'/>
51+
{% elif interface.type is not defined or interface.type == 'network' %}
3652
<interface type='network'>
3753
<source network='{{ interface.network }}'/>
3854
{% endif %}
55+
{% if interface.mac is defined %}
56+
<mac address='{{ interface.mac }}'/>
57+
{% endif %}
58+
{# if the network configuration is invalid this can still appear in the xml #}
59+
{# (say you enter 'bond' instead of 'bridge' in your variables) #}
3960
<model type='virtio'/>
4061
</interface>
4162
{% endfor %}
@@ -55,6 +76,11 @@
5576
<console type='pty'>
5677
<target type='serial' port='0'/>
5778
</console>
79+
{% endif %}
80+
{% if enable_vnc |bool %}
81+
<graphics type='vnc' autoport='yes' listen='127.0.0.1'>
82+
<listen type='address' address='127.0.0.1'/>
83+
</graphics>
5884
{% endif %}
5985
</devices>
6086
</domain>

0 commit comments

Comments
 (0)