Skip to content

Commit

Permalink
Merge pull request #19 from zoenglinghou/feature/kvm
Browse files Browse the repository at this point in the history
Feature: support for KVM on Linux
  • Loading branch information
andreygubarev authored Aug 22, 2023
2 parents dc50afa + aa5db95 commit dfdab93
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion molecule_qemu/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}"

tasks:
- name: Gather only necessary facts
ansible.builtin.setup:
gather_subset:
- "!all"
- "!min"
- architecture
- distribution

### configuration #########################################################

- name: Register VMs data
Expand Down Expand Up @@ -103,6 +111,7 @@
### capabilities ##########################################################

- name: Read kern.hv_support
when: ansible_system == 'Darwin'
ansible.builtin.command: sysctl kern.hv_support
register: hv_support
changed_when: false
Expand All @@ -111,7 +120,19 @@
- name: Set hvf support
ansible.builtin.set_fact:
qemu_cap_hvf: "{{ hv_support.stdout | trim == 'kern.hv_support: 1' }}"
when: hv_support is defined
when: hv_support is defined and ansible_system == 'Darwin'

- name: Check kvm support
when: ansible_system == 'Linux'
ansible.builtin.shell: (grep -q vmx /proc/cpuinfo || grep -q svm /proc/cpuinfo) && lsmod | grep -q kvm
register: kvm_support
changed_when: false
ignore_errors: true

- name: Set kvm support
ansible.builtin.set_fact:
qemu_cap_kvm: "{{ kvm_support is defined }}"
when: ansible_system == 'Linux'

### prerequisites #########################################################

Expand Down Expand Up @@ -261,6 +282,9 @@
-accel hvf
{% endif %}
{% endif %}
{% if qemu_cap_kvm and item.image_arch == ansible_machine %}
-enable-kvm
{% endif %}
args:
creates: "{{ item.path_pid }}"
loop: "{{ molecule_instances }}"
Expand Down

0 comments on commit dfdab93

Please sign in to comment.