zuul-airship-roles/roles/libvirt-domain/tasks/autodetect.yml
Kostiantyn Kalynovskyi 68157859a7 Add ansible roles for sushy and libvirt
This commit adds simple roles to manage:
 - libvirt service, domains, volumes, networks and pools.
 - redfish-emulator role installs sushy-tools from pip, together
   with support packages
Please note, that libvirt roles are not meant to be completely
idempotent, their main job is deploy temporary resources that for
ci and gating purposes, to be tore down afterwards. Roles are
specifically made to be simple to debug, and don't contain any
complex logic to make them portable, flexible or idempotent.

Change-Id: I2ff0138b5c95bea3445e242a2e5061651498f1ab
2020-01-13 23:08:11 +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