airshipctl/roles/libvirt-domain/tasks/autodetect.yaml
Alexander Hughes d5e28362f2 [#62] Standardize yaml file extensions
Currently we have mixed extensions of .yml and .yaml, this patch is
an effort to standardize all yaml documents as .yaml

Change-Id: I7eb815584de5856bbdac9a828ccad8518e8c1729
2020-02-24 14:50:32 +00:00

65 lines
2.1 KiB
YAML

---
- name: Detect the virtualisation engine
block:
- name: Load the kvm kernel module
modprobe:
name: kvm
become: true
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