Skip to content

Commit 534a51b

Browse files
authored
Merge branch 'master' into block-devices
2 parents d13fad7 + 9fab5e6 commit 534a51b

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Role Variables
113113
`libvirt_volume_default_format` are valid here. Default is
114114
`libvirt_volume_default_format`.
115115
- `image`: (optional) a URL to an image with which the volume is initalised (full copy).
116+
- `checksum`: (optional) checksum of the `image` to avoid download when it's not necessary.
116117
- `backing_image`: (optional) name of the backing volume which is assumed to already be the same pool (copy-on-write).
117118
- `image` and `backing_image` are mutually exclusive options.
118119
- `target`: (optional) Manually influence type and order of volumes

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ libvirt_vm_virsh_default_env: "{{ { 'LIBVIRT_DEFAULT_URI': libvirt_vm_uri } if
9292
# Override for the libvirt connection uri. Leave unset to use the default.
9393
libvirt_vm_uri: ""
9494

95+
# Whether to use sudo with libvirt commands, this can be disabled with qemu:///session
96+
# to create VMs as an unprivileged user
97+
libvirt_vm_sudo: true
98+
9599
# Default CPU mode if libvirt_vm_cpu_mode or vm.cpu_mode is undefined
96100
libvirt_cpu_mode_default: "{{ 'host-passthrough' if libvirt_vm_engine == 'kvm' else 'host-model' }}"
97101

tasks/vm.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
recurse: true
99
mode: 0770
1010
when: console_log_enabled | bool
11-
become: true
11+
become: "{{ libvirt_vm_sudo }}"
1212

1313
- name: Validate VM interfaces
1414
include_tasks: check-interface.yml
@@ -22,12 +22,12 @@
2222
command: define
2323
xml: "{{ lookup('template', vm.xml_file | default('vm.xml.j2')) }}"
2424
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
25-
become: true
25+
become: "{{ libvirt_vm_sudo }}"
2626

2727
- name: Ensure the VM is running and started at boot
2828
virt:
2929
name: "{{ vm.name }}"
3030
autostart: "{{ autostart | bool }}"
3131
state: "{{ 'running' if (start | bool) else 'shutdown' }}"
3232
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
33-
become: true
33+
become: "{{ libvirt_vm_sudo }}"

tasks/volumes.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
---
22
- name: Ensure remote images are downloaded
33
get_url:
4-
url: "{{ item }}"
5-
dest: "{{ libvirt_vm_image_cache_path }}/{{ item | basename }}"
6-
with_items: "{{ volumes | selectattr('image', 'defined') | map(attribute='image') | list }}"
7-
when: "'http' in item"
4+
url: "{{ item.image }}"
5+
dest: "{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}"
6+
checksum: "{{ item.checksum | default(omit) }}"
7+
with_items: "{{ volumes | selectattr('image', 'defined') | list }}"
8+
when: "'http' in item.image"
89

910
- name: Ensure local images are copied
1011
copy:
11-
src: "{{ item }}"
12-
dest: "{{ libvirt_vm_image_cache_path }}/{{ item | basename }}"
12+
src: "{{ item.image }}"
13+
dest: "{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}"
14+
checksum: "{{ item.checksum | default(omit) }}"
1315
remote_src: true
14-
with_items: "{{ volumes | selectattr('image', 'defined') | map(attribute='image') | list }}"
16+
with_items: "{{ volumes | selectattr('image', 'defined') | list }}"
1517
when: "'http' not in item"
1618

1719
- name: Ensure the VM disk volumes exist

0 commit comments

Comments
 (0)