Skip to content

Add the ability to run without sudo #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ libvirt_vm_virsh_default_env: "{{ { 'LIBVIRT_DEFAULT_URI': libvirt_vm_uri } if
# Override for the libvirt connection uri. Leave unset to use the default.
libvirt_vm_uri: ""

# Whether to use sudo with libvirt commands, this can be disabled with qemu:///session
# to create VMs as an unprivileged user
libvirt_vm_sudo: true

# Default CPU mode if libvirt_vm_cpu_mode or vm.cpu_mode is undefined
libvirt_cpu_mode_default: "{{ 'host-passthrough' if libvirt_vm_engine == 'kvm' else 'host-model' }}"

Expand Down
6 changes: 3 additions & 3 deletions tasks/vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
recurse: true
mode: 0770
when: console_log_enabled | bool
become: true
become: "{{ libvirt_vm_sudo }}"

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

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