Skip to content

Commit 548c27e

Browse files
authored
Merge pull request #97 from roumano/yamllint
Yamllint + ansible-lint
2 parents 022ec84 + 21492b5 commit 548c27e

File tree

10 files changed

+52
-48
lines changed

10 files changed

+52
-48
lines changed

defaults/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ libvirt_vm_default_console_log_dir: "/var/log/libvirt-consoles"
66

77
# Whether UUID should be calculated by hashing the VM name. If not, the UUID is
88
# randomly generated by libvirt when the VM is defined.
9-
libvirt_vm_default_uuid_deterministic: False
9+
libvirt_vm_default_uuid_deterministic: false
1010

1111
# The default location for libvirt images
1212
libvirt_volume_default_images_path: '/var/lib/libvirt/images'
@@ -42,7 +42,7 @@ libvirt_vm_emulator:
4242
# Default value for clock syncing. The default (false) uses <clock sync="localtime">
4343
# to configure the instances clock synchronisation. Change to a timezone to make
4444
# configuration use <clock offset="specified offset">
45-
libvirt_vm_clock_offset: False
45+
libvirt_vm_clock_offset: false
4646

4747
# Default value for whether to trust guest receive filters. This gets mapped to
4848
# the trustGuestRxFilters attribute of VM interfaces.
@@ -53,7 +53,7 @@ libvirt_vm_trust_guest_rx_filters: false
5353
# the values of the deprecated variables below.
5454
# See README.md or tasks/main.yml for these attributes' defaults.
5555
libvirt_vms:
56-
# State of the VM. May be 'present' or 'absent'.
56+
# State of the VM. May be 'present' or 'absent'.
5757
- state: "{{ libvirt_vm_state }}"
5858

5959
# Name of the VM.
@@ -85,7 +85,7 @@ libvirt_vms:
8585

8686
# XML template file to source domain definition
8787
xml_file: vm.xml.j2
88-
88+
8989
# May be one of: bios, or efi.
9090
boot_firmware: bios
9191

@@ -113,6 +113,6 @@ libvirt_vm_volumes:
113113
libvirt_vm_interfaces:
114114
libvirt_vm_console_log_path:
115115
# Required, so we should fail if not set.
116-
#libvirt_vm_name:
117-
#libvirt_vm_memory_mb:
118-
#libvirt_vm_vcpus:
116+
# libvirt_vm_name:
117+
# libvirt_vm_memory_mb:
118+
# libvirt_vm_vcpus:

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
galaxy_info:
3-
#role_name: libvirt_vm
3+
# role_name: libvirt_vm
44
author: Mark Goddard
55
description: >
66
Role to configure and create VMs on a Libvirt/KVM hypervisor

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: 3 additions & 3 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
6-
changed_when: false
6+
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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@
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
10-
become: yes
10+
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) }}"
18-
become: yes
19+
become: true
1920

2021
# note(wszumski): the virt module does not seem to support
2122
# removing vms with nvram defined - as a workaround, use the
2223
# virsh cli directly. It may be better to detect if dumpxml
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 %}
3031
undefine
3132
{% if boot_firmware == 'efi' %} --nvram{% endif %}
3233
{{ vm.name }}
33-
become: yes
34+
become: true
3435
changed_when: true
3536
when: vm.name in result.list_vms

tasks/destroy-volumes.yml

Lines changed: 2 additions & 2 deletions
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') }}
@@ -11,4 +11,4 @@
1111
changed_when:
1212
- volume_result is success
1313
- (volume_result.stdout | from_json).changed | default(True)
14-
become: yes
14+
become: true

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: 6 additions & 6 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') }}
@@ -36,11 +36,11 @@
3636
changed_when:
3737
- volume_result is success
3838
- (volume_result.stdout | from_json).changed | default(True)
39-
check_mode: False
39+
check_mode: false
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
@@ -49,5 +49,5 @@
4949
changed_when:
5050
- volume_result_network is success
5151
- volume_result_network.rc == 1
52-
check_mode: False
52+
check_mode: false
5353
become: true

0 commit comments

Comments
 (0)