|
8 | 8 | failed_when: false |
9 | 9 |
|
10 | 10 | - name: Check for the KVM device |
11 | | - stat: |
| 11 | + ansible.builtin.stat: |
12 | 12 | path: /dev/kvm |
13 | 13 | register: stat_kvm |
14 | 14 |
|
15 | 15 | - name: Set a fact containing the virtualisation engine |
16 | | - set_fact: |
| 16 | + ansible.builtin.set_fact: |
17 | 17 | libvirt_vm_engine: >- |
18 | 18 | {%- if ansible_facts.architecture != libvirt_vm_arch -%} |
19 | 19 | {# Virtualisation instructions are generally available only for the host |
|
30 | 30 |
|
31 | 31 | - name: Detect the virtualisation emulator |
32 | 32 | block: |
33 | | - - block: |
| 33 | + - name: Set fact when vm engine is kvm |
| 34 | + block: |
34 | 35 | - name: Detect the KVM emulator binary path |
35 | | - stat: |
| 36 | + ansible.builtin.stat: |
36 | 37 | path: "{{ item }}" |
37 | 38 | register: kvm_emulator_result |
38 | 39 | with_items: |
|
41 | 42 | - /usr/libexec/qemu-kvm |
42 | 43 |
|
43 | 44 | - name: Set a fact containing the KVM emulator binary path |
44 | | - set_fact: |
| 45 | + ansible.builtin.set_fact: |
45 | 46 | libvirt_vm_emulator: "{{ item.item }}" |
46 | 47 | with_items: "{{ kvm_emulator_result.results }}" |
47 | 48 | when: item.stat.exists |
48 | 49 | when: libvirt_vm_engine == 'kvm' |
49 | 50 |
|
50 | | - - block: |
| 51 | + - name: Set a fact when RedHat and vm engine is qemu |
| 52 | + block: |
51 | 53 | - name: Detect the QEMU emulator binary path |
52 | | - stat: |
| 54 | + ansible.builtin.stat: |
53 | 55 | path: /usr/libexec/qemu-kvm |
54 | 56 | register: kvm_emulator_result |
55 | 57 |
|
56 | 58 | - name: Set a fact containing the QEMU emulator binary path |
57 | | - set_fact: |
| 59 | + ansible.builtin.set_fact: |
58 | 60 | libvirt_vm_emulator: "{{ kvm_emulator_result.stat.path }}" |
59 | 61 | when: kvm_emulator_result.stat.exists |
60 | 62 | when: |
61 | 63 | - libvirt_vm_engine == 'qemu' |
62 | 64 | - ansible_facts.os_family == 'RedHat' |
63 | 65 | - ansible_facts.distribution_major_version | int >= 8 |
64 | 66 |
|
65 | | - - block: |
| 67 | + - name: Set a fact when not RedHat and vm engine is qemu |
| 68 | + block: |
66 | 69 | - name: Detect the QEMU emulator binary path |
67 | | - shell: which qemu-system-{{ libvirt_vm_arch }} |
| 70 | + ansible.builtin.shell: which qemu-system-{{ libvirt_vm_arch }} |
68 | 71 | register: qemu_emulator_result |
69 | 72 | changed_when: false |
70 | 73 |
|
71 | 74 | - name: Set a fact containing the QEMU emulator binary path |
72 | | - set_fact: |
| 75 | + ansible.builtin.set_fact: |
73 | 76 | libvirt_vm_emulator: "{{ qemu_emulator_result.stdout }}" |
74 | 77 |
|
75 | 78 | when: |
76 | 79 | - libvirt_vm_engine == 'qemu' |
77 | 80 | - ansible_facts.os_family != 'RedHat' or ansible_facts.distribution_major_version | int == 7 |
78 | 81 |
|
79 | 82 | - name: Fail if unable to detect the emulator |
80 | | - fail: |
| 83 | + ansible.builtin.fail: |
81 | 84 | msg: Unable to detect emulator for engine {{ libvirt_vm_engine }}. |
82 | 85 | when: libvirt_vm_emulator is none |
83 | 86 | when: libvirt_vm_emulator is none or libvirt_vm_emulator | length == 0 |
0 commit comments