Skip to content

Commit 66470cc

Browse files
committed
set FQCN on all calls
1 parent d8aa2e4 commit 66470cc

File tree

11 files changed

+68
-32
lines changed

11 files changed

+68
-32
lines changed

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ libvirt_vms:
8686
# XML template file to source domain definition
8787
xml_file: vm.xml.j2
8888

89+
# May be one of: bios, or efi.
90+
boot_firmware: bios
91+
8992
# Variables to add to the enviroment that is used to execute virsh commands
9093
libvirt_vm_virsh_default_env: "{{ { 'LIBVIRT_DEFAULT_URI': libvirt_vm_uri } if libvirt_vm_uri else {} }}"
9194

tasks/autodetect.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
- name: Detect the virtualisation engine
33
block:
44
- name: Load the kvm kernel module
5-
modprobe:
5+
community.general.modprobe:
66
name: kvm
77
become: true
88
failed_when: false
99

1010
- name: Check for the KVM device
11-
stat:
11+
ansible.builtin.stat:
1212
path: /dev/kvm
1313
register: stat_kvm
1414

1515
- name: Set a fact containing the virtualisation engine
16-
set_fact:
16+
ansible.builtin.set_fact:
1717
libvirt_vm_engine: >-
1818
{%- if ansible_facts.architecture != libvirt_vm_arch -%}
1919
{# Virtualisation instructions are generally available only for the host
@@ -32,7 +32,7 @@
3232
block:
3333
- block:
3434
- name: Detect the KVM emulator binary path
35-
stat:
35+
ansible.builtin.stat:
3636
path: "{{ item }}"
3737
register: kvm_emulator_result
3838
with_items:
@@ -49,12 +49,12 @@
4949

5050
- block:
5151
- name: Detect the QEMU emulator binary path
52-
stat:
52+
ansible.builtin.stat:
5353
path: /usr/libexec/qemu-kvm
5454
register: kvm_emulator_result
5555

5656
- name: Set a fact containing the QEMU emulator binary path
57-
set_fact:
57+
ansible.builtin.set_fact:
5858
libvirt_vm_emulator: "{{ kvm_emulator_result.stat.path }}"
5959
when: kvm_emulator_result.stat.exists
6060
when:
@@ -64,7 +64,7 @@
6464

6565
- block:
6666
- name: Detect the QEMU emulator binary path
67-
shell: which qemu-system-{{ libvirt_vm_arch }}
67+
ansible.builtin.command: "which qemu-system-{{ libvirt_vm_arch }}"
6868
register: qemu_emulator_result
6969
changed_when: false
7070

@@ -77,7 +77,7 @@
7777
- ansible_facts.os_family != 'RedHat' or ansible_facts.distribution_major_version | int == 7
7878

7979
- name: Fail if unable to detect the emulator
80-
fail:
80+
ansible.builtin.fail:
8181
msg: Unable to detect emulator for engine {{ libvirt_vm_engine }}.
8282
when: libvirt_vm_emulator is none
8383
when: libvirt_vm_emulator is none or libvirt_vm_emulator | length == 0

tasks/check-interface.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Check network interface has a network name
3-
fail:
3+
ansible.builtin.fail:
44
msg: >
55
The interface definition {{ interface }} has type 'network', but does not have
66
a network name defined.
@@ -10,7 +10,7 @@
1010
- interface.network is not defined
1111

1212
- name: Check direct interface has an interface device name
13-
fail:
13+
ansible.builtin.fail:
1414
msg: >
1515
The interface definition {{ interface }} has type 'direct', but does not have
1616
a host source device defined.

tasks/destroy-vm.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# The destroyed state does not seem to be idempotent, so check whether the VM
33
# exists before destroying it.
44
- name: Check the VM's status
5-
virt:
5+
community.libvirt.virt:
66
name: "{{ vm.name }}"
77
command: list_vms
88
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
@@ -11,16 +11,25 @@
1111

1212
- block:
1313
- name: Ensure the VM is absent
14-
virt:
14+
community.libvirt.virt:
1515
name: "{{ vm.name }}"
1616
state: destroyed
1717
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
1818
become: yes
1919

20+
# note(wszumski): the virt module does not seem to support
21+
# removing vms with nvram defined - as a workaround, use the
22+
# virsh cli directly. It may be better to detect if dumpxml
23+
# actually contains an nvram element rather than relying on
24+
# boot_firmware having the correct value.
2025
- name: Ensure the VM is undefined
21-
virt:
22-
name: "{{ vm.name }}"
23-
command: undefine
24-
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
26+
community.libvirt.command:
27+
cmd: >-
28+
virsh
29+
{% if libvirt_vm_uri %}-c {{ libvirt_vm_uri }}{% endif %}
30+
undefine
31+
{% if boot_firmware == 'efi' %} --nvram{% endif %}
32+
{{ vm.name }}
2533
become: yes
34+
changed_when: true
2635
when: vm.name in result.list_vms

tasks/destroy-volumes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Ensure the VM volumes do not exist
3-
script: >
3+
ansible.builtin.script: >
44
destroy_virt_volume.sh
55
{{ item.name }}
66
{{ item.pool | default('default') }}

tasks/main.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
- name: Gather os specific variables
3-
include_vars: "{{ item }}"
3+
ansible.builtin.include_vars: "{{ item }}"
44
with_first_found:
55
- files:
66
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
77
- "{{ ansible_facts.distribution }}.yml"
88
- "{{ ansible_facts.os_family }}.yml"
99
tags: vars
1010

11-
- include_tasks: autodetect.yml
11+
- ansible.builtin.include_tasks: autodetect.yml
1212
# We don't need to know the engine and emulator if we're not creating any new
1313
# VMs.
1414
when: >-
@@ -17,20 +17,20 @@
1717
1818
# Libvirt requires qemu-img to create qcow2 files.
1919
- name: Ensure qemu-img is installed
20-
package:
20+
ansible.builtin.package:
2121
name: "{{ 'qemu-img' if ansible_facts.os_family == 'RedHat' else 'qemu-utils' }}"
2222
update_cache: "{{ True if ansible_facts.pkg_mgr == 'apt' else omit }}"
2323
become: true
2424

25-
- include_tasks: volumes.yml
25+
- ansible.builtin.include_tasks: volumes.yml
2626
vars:
2727
volumes: "{{ vm.volumes | default([], true) }}"
2828
with_items: "{{ libvirt_vms }}"
2929
loop_control:
3030
loop_var: vm
3131
when: (vm.state | default('present', true)) == 'present'
3232

33-
- include_tasks: vm.yml
33+
- ansible.builtin.include_tasks: vm.yml
3434
vars:
3535
console_log_enabled: "{{ vm.console_log_enabled | default(false) }}"
3636
console_log_path: >-
@@ -45,18 +45,21 @@
4545
autostart: "{{ vm.autostart | default(true) }}"
4646
enable_vnc: "{{ vm.enable_vnc | default(false) }}"
4747
enable_spice: "{{ vm.enable_spice | default(false) }}"
48+
boot_firmware: "{{ vm.boot_firmware | default('bios', true) | lower }}"
4849
with_items: "{{ libvirt_vms }}"
4950
loop_control:
5051
loop_var: vm
5152
when: (vm.state | default('present', true)) == 'present'
5253

53-
- include_tasks: destroy-vm.yml
54+
- ansible.builtin.include_tasks: destroy-vm.yml
55+
vars:
56+
boot_firmware: "{{ vm.boot_firmware | default('bios', true) | lower }}"
5457
with_items: "{{ libvirt_vms }}"
5558
loop_control:
5659
loop_var: vm
5760
when: (vm.state | default('present', true)) == 'absent'
5861

59-
- include_tasks: destroy-volumes.yml
62+
- ansible.builtin.include_tasks: destroy-volumes.yml
6063
vars:
6164
volumes: "{{ vm.volumes | default([], true) }}"
6265
with_items: "{{ libvirt_vms }}"

tasks/vm.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Ensure the VM console log directory exists
3-
file:
3+
ansible.builtin.file:
44
path: "{{ console_log_path | dirname }}"
55
state: directory
66
owner: "{{ libvirt_vm_log_owner }}"
@@ -11,21 +11,21 @@
1111
become: "{{ libvirt_vm_sudo }}"
1212

1313
- name: Validate VM interfaces
14-
include_tasks: check-interface.yml
14+
ansible.builtin.include_tasks: check-interface.yml
1515
vars:
1616
interface: "{{ item }}"
1717
with_items: "{{ interfaces }}"
1818

1919
- name: Ensure the VM is defined
20-
virt:
20+
community.libvirt.virt:
2121
name: "{{ vm.name }}"
2222
command: define
2323
xml: "{{ lookup('template', vm.xml_file | default('vm.xml.j2')) }}"
2424
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
2525
become: "{{ libvirt_vm_sudo }}"
2626

2727
- name: Ensure the VM is running and started at boot
28-
virt:
28+
community.libvirt.virt:
2929
name: "{{ vm.name }}"
3030
autostart: "{{ autostart | bool }}"
3131
state: "{{ 'running' if (start | bool) else 'shutdown' }}"

tasks/volumes.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
- name: Ensure remote images are downloaded
3-
get_url:
3+
ansible.builtin.get_url:
44
url: "{{ item.image }}"
55
dest: "{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}"
66
checksum: "{{ item.checksum | default(omit) }}"
77
with_items: "{{ volumes | selectattr('image', 'defined') | list }}"
88
when: "'http' in item.image"
99

1010
- name: Ensure local images are copied
11-
copy:
11+
ansible.builtin.copy:
1212
src: "{{ item.image }}"
1313
dest: "{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}"
1414
checksum: "{{ item.checksum | default(omit) }}"
@@ -17,7 +17,7 @@
1717
when: "'http' not in item.image"
1818

1919
- name: Ensure the VM disk volumes exist
20-
script: >
20+
ansible.builtin.script: >
2121
virt_volume.sh
2222
-n {{ item.name }}
2323
-p {{ item.pool |default('default') }}
@@ -40,7 +40,7 @@
4040
become: true
4141

4242
- name: Ensure the VM network volumes exist
43-
command: qemu-img create -f {{ item.source.protocol }} {{ item.source.protocol }}:{{ item.source.name }} {{ item.capacity }}
43+
ansible.builtin.command: qemu-img create -f {{ item.source.protocol }} {{ item.source.protocol }}:{{ item.source.name }} {{ item.capacity }}
4444
with_items: "{{ volumes }}"
4545
when: item.type | default(libvirt_volume_default_type) == 'network'
4646
register: volume_result_network

vars/Archlinux.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ libvirt_vm_script_env: >-
1010
1111
# Archlinux qemu comes with kvm support compiled in
1212
libvirt_vm_emulator: /usr/bin/qemu-system-x86_64
13+
14+
# Path to template OVMF efi variable store. A copy will be created
15+
# for each VM created.
16+
libvirt_vm_ovmf_efi_variable_store_path: /usr/share/OVMF/OVMF_VARS.fd
17+
18+
# Path to OVMF efi firmware
19+
libvirt_vm_ovmf_efi_firmware_path: /usr/share/OVMF/OVMF_CODE.fd

vars/Debian.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ libvirt_vm_script_env_debian:
1010

1111
libvirt_vm_script_env: >-
1212
{{ libvirt_vm_script_env_debian | combine(libvirt_vm_virsh_default_env) }}
13+
14+
# Path to template OVMF efi variable store. A copy will be created
15+
# for each VM created.
16+
libvirt_vm_ovmf_efi_variable_store_path: /usr/share/OVMF/OVMF_VARS.fd
17+
18+
# Path to OVMF efi firmware
19+
libvirt_vm_ovmf_efi_firmware_path: /usr/share/OVMF/OVMF_CODE.fd

vars/RedHat.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ libvirt_vm_script_env_redhat:
1010

1111
libvirt_vm_script_env: >-
1212
{{ libvirt_vm_script_env_redhat | combine(libvirt_vm_virsh_default_env) }}
13+
14+
# Path to template OVMF efi variable store. A copy will be created
15+
# for each VM created.
16+
libvirt_vm_ovmf_efi_variable_store_path: /usr/share/edk2/ovmf/OVMF_VARS.fd
17+
18+
# Path to OVMF efi firmware
19+
libvirt_vm_ovmf_efi_firmware_path: /usr/share/edk2/ovmf/OVMF_CODE.cc.fd

0 commit comments

Comments
 (0)