Skip to content

Commit 21492b5

Browse files
author
Christian Iuga
committed
Pass ansible-lint on the role
Fix these warning/error: - All tasks should be named. - Use FQCN for builtin actions.
1 parent 9bc9aaf commit 21492b5

File tree

8 files changed

+37
-33
lines changed

8 files changed

+37
-33
lines changed

tasks/autodetect.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
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
@@ -30,9 +30,10 @@
3030

3131
- name: Detect the virtualisation emulator
3232
block:
33-
- block:
33+
- name: Set fact when vm engine is kvm
34+
block:
3435
- name: Detect the KVM emulator binary path
35-
stat:
36+
ansible.builtin.stat:
3637
path: "{{ item }}"
3738
register: kvm_emulator_result
3839
with_items:
@@ -41,43 +42,45 @@
4142
- /usr/libexec/qemu-kvm
4243

4344
- name: Set a fact containing the KVM emulator binary path
44-
set_fact:
45+
ansible.builtin.set_fact:
4546
libvirt_vm_emulator: "{{ item.item }}"
4647
with_items: "{{ kvm_emulator_result.results }}"
4748
when: item.stat.exists
4849
when: libvirt_vm_engine == 'kvm'
4950

50-
- block:
51+
- name: Set a fact when RedHat and vm engine is qemu
52+
block:
5153
- name: Detect the QEMU emulator binary path
52-
stat:
54+
ansible.builtin.stat:
5355
path: /usr/libexec/qemu-kvm
5456
register: kvm_emulator_result
5557

5658
- name: Set a fact containing the QEMU emulator binary path
57-
set_fact:
59+
ansible.builtin.set_fact:
5860
libvirt_vm_emulator: "{{ kvm_emulator_result.stat.path }}"
5961
when: kvm_emulator_result.stat.exists
6062
when:
6163
- libvirt_vm_engine == 'qemu'
6264
- ansible_facts.os_family == 'RedHat'
6365
- ansible_facts.distribution_major_version | int >= 8
6466

65-
- block:
67+
- name: Set a fact when not RedHat and vm engine is qemu
68+
block:
6669
- 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 }}
6871
register: qemu_emulator_result
6972
changed_when: false
7073

7174
- name: Set a fact containing the QEMU emulator binary path
72-
set_fact:
75+
ansible.builtin.set_fact:
7376
libvirt_vm_emulator: "{{ qemu_emulator_result.stdout }}"
7477

7578
when:
7679
- libvirt_vm_engine == 'qemu'
7780
- ansible_facts.os_family != 'RedHat' or ansible_facts.distribution_major_version | int == 7
7881

7982
- name: Fail if unable to detect the emulator
80-
fail:
83+
ansible.builtin.fail:
8184
msg: Unable to detect emulator for engine {{ libvirt_vm_engine }}.
8285
when: libvirt_vm_emulator is none
8386
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/check-usb-devices.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
- name: List USB hardware
3-
command: lsusb -d {{ usb_device.vendor }}:{{ usb_device.product }}
3+
ansible.builtin.command: lsusb -d {{ usb_device.vendor }}:{{ usb_device.product }}
44
register: host_attached_usb_device
55
become: true
66
changed_when: false
77
failed_when: false
88

99
- name: Check USB device is present on Host system
10-
fail:
10+
ansible.builtin.fail:
1111
msg: >
1212
The USB Device with Vendor ID:{{ usb_device.vendor }} and Product ID:{{ usb_device.product }} is not seen on host system
1313
Is the USB device plugged in correctly ?

tasks/destroy-vm.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
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) }}"
99
register: result
1010
become: true
1111

12-
- block:
12+
- name: Destory the VM is existing
13+
block:
1314
- name: Ensure the VM is absent
14-
virt:
15+
community.libvirt.virt:
1516
name: "{{ vm.name }}"
1617
state: destroyed
1718
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
@@ -23,7 +24,7 @@
2324
# actually contains an nvram element rather than relying on
2425
# boot_firmware having the correct value.
2526
- name: Ensure the VM is undefined
26-
command:
27+
ansible.builtin.command:
2728
cmd: >-
2829
virsh
2930
{% if libvirt_vm_uri %}-c {{ libvirt_vm_uri }}{% endif %}

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: 3 additions & 3 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,7 +17,7 @@
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

tasks/vm.yml

Lines changed: 5 additions & 5 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,26 +11,26 @@
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: Validate Host USB Devices
20-
include_tasks: check-usb-devices.yml
20+
ansible.builtin.include_tasks: check-usb-devices.yml
2121
vars:
2222
usb_device: "{{ item }}"
2323
with_items: "{{ usb_devices }}"
2424

2525
- name: Ensure the VM is defined
26-
virt:
26+
community.libvirt.virt:
2727
command: define
2828
xml: "{{ lookup('template', vm.xml_file | default('vm.xml.j2')) }}"
2929
uri: "{{ libvirt_vm_uri | default(omit, true) }}"
3030
become: "{{ libvirt_vm_sudo }}"
3131

3232
- name: Ensure the VM is running and started at boot
33-
virt:
33+
community.libvirt.virt:
3434
name: "{{ vm.name }}"
3535
autostart: "{{ autostart | bool }}"
3636
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

0 commit comments

Comments
 (0)