# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. --- - name: Detect the virtualisation engine block: - name: Load the kvm kernel module modprobe: name: kvm become: yes failed_when: false - name: Check for the KVM device stat: path: /dev/kvm register: stat_kvm - name: Set a fact containing the virtualisation engine set_fact: libvirt_vm_engine: >- {%- if ansible_architecture != libvirt_vm_arch -%} {# Virtualisation instructions are generally available only for the host architecture. Ideally we would test for virtualisation instructions, eg. vt-d as it is possible that another architecture could support these even if the emulated cpu architecture is not the same. #} qemu {%- elif stat_kvm.stat.exists -%} kvm {%- else -%} qemu {%- endif -%} when: libvirt_vm_engine is none or libvirt_vm_engine | length == 0 - name: Detect the virtualisation emulator block: - block: - name: Detect the KVM emulator binary path stat: path: "{{ item }}" register: kvm_emulator_result with_items: - /usr/bin/kvm - /usr/bin/qemu-kvm - /usr/libexec/qemu-kvm - name: Set a fact containing the KVM emulator binary path set_fact: libvirt_vm_emulator: "{{ item.item }}" with_items: "{{ kvm_emulator_result.results }}" when: item.stat.exists when: libvirt_vm_engine == 'kvm' - block: - name: Detect the QEMU emulator binary path shell: which qemu-system-{{ libvirt_vm_arch }} register: qemu_emulator_result changed_when: false - name: Set a fact containing the QEMU emulator binary path set_fact: libvirt_vm_emulator: "{{ qemu_emulator_result.stdout }}" when: libvirt_vm_engine == 'qemu' - name: Fail if unable to detect the emulator fail: msg: Unable to detect emulator for engine {{ libvirt_vm_engine }}. when: libvirt_vm_emulator is none when: libvirt_vm_emulator is none or libvirt_vm_emulator | length == 0