Skip to content

Commit 8d8c78c

Browse files
authored
Merge pull request #71 from michaeltchapman/master
Add the ability to run without sudo
2 parents 7f21f73 + faeb0d1 commit 8d8c78c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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 }}"

0 commit comments

Comments
 (0)