[PATCH 02/13] qemu: make the role a first-class lint pass

Daniel Gomez <[email protected]> Fri, 12 Jun 2026 14:36:40 +0200
Newsgroups dev.linux.lists.kdevops
Message-ID <[email protected]>
From: Daniel Gomez <[email protected]>

Bring the qemu role up to the ansible-lint production profile without
any noqa waivers. Qualify become_method as ansible.builtin.sudo, set
changed_when on the command and stat tasks, turn the include_vars
ignore_errors into failed_when, name every import_tasks, and give the
git fetch a literal string and the install dir an explicit mode.

Drop the redundant qemu_build enable variable. The role only ever runs
under the CONFIG_QEMU_BUILD make guard, so the per-task qemu_build|bool
gates were dead weight; removing them also lets qemu_build_now key off
the real stat result instead of a guard that only held while the stat
was skipped. Trim the unused build_linux_* leftovers from the defaults
and the unused is_sle and is_leap SUSE facts, renaming the one fact we
keep to qemu_is_tumbleweed.

Generated-by: Claude AI
Signed-off-by: Daniel Gomez <[email protected]>
---
 playbooks/roles/qemu/defaults/main.yml             |  7 +----
 .../roles/qemu/tasks/install-deps/debian/main.yml  |  4 +--
 .../roles/qemu/tasks/install-deps/fedora/main.yml  |  2 +-
 playbooks/roles/qemu/tasks/install-deps/main.yml   | 16 +++++++----
 .../roles/qemu/tasks/install-deps/redhat/main.yml  |  2 +-
 .../roles/qemu/tasks/install-deps/suse/main.yml    | 10 +++----
 playbooks/roles/qemu/tasks/main.yml                | 32 +++++++++++-----------
 7 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/playbooks/roles/qemu/defaults/main.yml b/playbooks/roles/qemu/defaults/main.yml
index 7ff9e996..07fe4802 100644
--- a/playbooks/roles/qemu/defaults/main.yml
+++ b/playbooks/roles/qemu/defaults/main.yml
@@ -1,10 +1,7 @@
 # SPDX-License-Identifier: copyleft-next-0.3.1
 ---
 
-qemu_build: false
-
-# Forces to build and install even if the file
-# /usr/local/bin/qemu-system-x86_64 is already present
+# Forces to build and install even if the binary is already present
 qemu_force_install_if_present: false
 qemu_bin_path: "/usr/local/bin/qemu-system-x86_64"
 qemu_data: "{{ data_path }}/qemu"
@@ -12,5 +9,3 @@ qemu_git: "https://github.com/qemu/qemu.git"
 qemu_version: "v7.2.0-rc4"
 qemu_build_dir: "{{ qemu_data }}/build"
 qemu_target: "x86_64-softmmu"
-build_linux_shallow_clone: true
-build_linux_clone_depth: 1
diff --git a/playbooks/roles/qemu/tasks/install-deps/debian/main.yml b/playbooks/roles/qemu/tasks/install-deps/debian/main.yml
index 46f5a720..e40f5aa6 100644
--- a/playbooks/roles/qemu/tasks/install-deps/debian/main.yml
+++ b/playbooks/roles/qemu/tasks/install-deps/debian/main.yml
@@ -2,14 +2,14 @@
 # SPDX-License-Identifier: copyleft-next-0.3.1
 - name: Update apt cache
   become: true
-  become_method: sudo
+  become_method: ansible.builtin.sudo
   ansible.builtin.apt:
     update_cache: true
   tags: ["qemu", "update-cache"]
 
 - name: Install QEMU build dependencies
   become: true
-  become_method: sudo
+  become_method: ansible.builtin.sudo
   ansible.builtin.apt:
     name:
       - debhelper-compat
diff --git a/playbooks/roles/qemu/tasks/install-deps/fedora/main.yml b/playbooks/roles/qemu/tasks/install-deps/fedora/main.yml
index 7cd43bf8..7b583ddc 100644
--- a/playbooks/roles/qemu/tasks/install-deps/fedora/main.yml
+++ b/playbooks/roles/qemu/tasks/install-deps/fedora/main.yml
@@ -9,7 +9,7 @@
 
 - name: Install QEMU build dependencies
   become: true
-  become_method: sudo
+  become_method: ansible.builtin.sudo
   ansible.builtin.dnf:
     name:
       - ImageMagick
diff --git a/playbooks/roles/qemu/tasks/install-deps/main.yml b/playbooks/roles/qemu/tasks/install-deps/main.yml
index 38747d88..fe41be98 100644
--- a/playbooks/roles/qemu/tasks/install-deps/main.yml
+++ b/playbooks/roles/qemu/tasks/install-deps/main.yml
@@ -2,21 +2,27 @@
 # SPDX-License-Identifier: copyleft-next-0.3.1
 - name: Import optional distribution specific variables
   ansible.builtin.include_vars: "{{ item }}"
-  ignore_errors: true
+  failed_when: false
   with_first_found:
     - files:
         - "{{ ansible_facts['os_family'] | lower }}.yml"
       skip: true
   tags: vars
 
-- name: Distribution specific setup
+- name: Install QEMU build dependencies on Debian
   ansible.builtin.import_tasks: debian/main.yml
   when: ansible_facts['os_family']|lower == 'debian'
-- ansible.builtin.import_tasks: suse/main.yml
+
+- name: Install QEMU build dependencies on SUSE
+  ansible.builtin.import_tasks: suse/main.yml
   when: ansible_facts['os_family']|lower == 'suse'
-- ansible.builtin.import_tasks: redhat/main.yml
+
+- name: Install QEMU build dependencies on Red Hat
+  ansible.builtin.import_tasks: redhat/main.yml
   when:
     - ansible_facts['os_family']|lower == 'redhat'
     - ansible_facts['distribution']|lower != "fedora"
-- ansible.builtin.import_tasks: fedora/main.yml
+
+- name: Install QEMU build dependencies on Fedora
+  ansible.builtin.import_tasks: fedora/main.yml
   when: ansible_facts['distribution']|lower == "fedora"
diff --git a/playbooks/roles/qemu/tasks/install-deps/redhat/main.yml b/playbooks/roles/qemu/tasks/install-deps/redhat/main.yml
index e2cefccd..34695c2c 100644
--- a/playbooks/roles/qemu/tasks/install-deps/redhat/main.yml
+++ b/playbooks/roles/qemu/tasks/install-deps/redhat/main.yml
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: copyleft-next-0.3.1
 - name: Install QEMU build dependencies
   become: true
-  become_method: sudo
+  become_method: ansible.builtin.sudo
   ansible.builtin.dnf:
     name:
       - glusterfs-common
diff --git a/playbooks/roles/qemu/tasks/install-deps/suse/main.yml b/playbooks/roles/qemu/tasks/install-deps/suse/main.yml
index 7edf8999..caaa8121 100644
--- a/playbooks/roles/qemu/tasks/install-deps/suse/main.yml
+++ b/playbooks/roles/qemu/tasks/install-deps/suse/main.yml
@@ -1,14 +1,12 @@
 ---
 # SPDX-License-Identifier: copyleft-next-0.3.1
-- name: Set generic SUSE specific distro facts
+- name: Set SUSE distribution facts
   ansible.builtin.set_fact:
-    is_sle: '{{ (ansible_distribution == "SLES") or (ansible_distribution == "SLED") }}'
-    is_leap: '{{ "Leap" in ansible_distribution }}'
-    is_tumbleweed: '{{ "openSUSE Tumbleweed" == ansible_distribution }}'
+    qemu_is_tumbleweed: '{{ "openSUSE Tumbleweed" == ansible_distribution }}'
 
 - name: Install QEMU build dependencies
   become: true
-  become_method: sudo
+  become_method: ansible.builtin.sudo
   ansible.builtin.package:
     name:
       - acpica
@@ -418,4 +416,4 @@
       - zlib-devel
     state: present
   when:
-    - is_tumbleweed
+    - qemu_is_tumbleweed
diff --git a/playbooks/roles/qemu/tasks/main.yml b/playbooks/roles/qemu/tasks/main.yml
index 94d5f023..005d8637 100644
--- a/playbooks/roles/qemu/tasks/main.yml
+++ b/playbooks/roles/qemu/tasks/main.yml
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: copyleft-next-0.3.1
 - name: Import optional extra_args file
   ansible.builtin.include_vars: "{{ item }}"
-  ignore_errors: true
+  failed_when: false
   with_first_found:
     - files:
         - "../extra_vars.yml"
@@ -15,16 +15,13 @@
   ansible.builtin.stat:
     path: "{{ qemu_bin_path }}"
   register: qemu_present
-  changed_when: true
+  changed_when: false
   failed_when: qemu_present.stat.exists and not qemu_present.stat.executable
   tags: ["qemu", "verify"]
-  when:
-    - qemu_build|bool
 
 - name: Install build-deps for QEMU as per each Linux distribution
   ansible.builtin.include_tasks: install-deps/main.yml
   when:
-    - qemu_build|bool
     - qemu_force_install_if_present|bool or not qemu_present.stat.exists
 
 - name: Assume we won't build QEMU first
@@ -36,21 +33,21 @@
   ansible.builtin.set_fact:
     qemu_build_now: true
   when:
-    - qemu_build|bool
-    - qemu_force_install_if_present|bool or (qemu_present.stat is not defined)
+    - qemu_force_install_if_present|bool or not qemu_present.stat.exists
   tags: vars
 
-- name: Ensure that {{ local_dev_path }} exists
+- name: Ensure the local development path exists
   ansible.builtin.file:
     path: "{{ local_dev_path }}"
     state: directory
+    mode: "0755"
   tags: ["qemu", "build-deps"]
   when:
     - qemu_build_now|bool
 
-- name: Git fetch QEMU using {{ qemu_git }} on {{ qemu_data }}
+- name: Fetch the QEMU git tree
   environment:
-    GIT_SSL_NO_VERIFY: true
+    GIT_SSL_NO_VERIFY: "true"
   ansible.builtin.git:
     repo: "{{ qemu_git }}"
     dest: "{{ qemu_data }}"
@@ -66,8 +63,9 @@
   when:
     - qemu_build_now|bool
 
-- name: Disable downloads
+- name: Pre-fetch QEMU subprojects so configure can disable downloads
   ansible.builtin.command: "meson subprojects download"
+  changed_when: true
   tags: ["qemu", "configure"]
   args:
     chdir: "{{ qemu_data }}"
@@ -76,32 +74,34 @@
 
 - name: Run configure for QEMU
   ansible.builtin.command: "./configure --target-list={{ qemu_target }} --disable-download"
+  changed_when: true
   tags: ["qemu", "configure"]
   args:
     chdir: "{{ qemu_data }}"
   when:
     - qemu_build_now|bool
 
-- name: Get nproc
+- name: Get the number of build jobs
   ansible.builtin.command: "{{ num_jobs }}"
+  changed_when: false
   tags: ["qemu", "configure", "build"]
-  register: nproc
+  register: qemu_nproc
   when:
     - qemu_build_now|bool
 
 - name: Build QEMU
   community.general.make:
     chdir: "{{ qemu_data }}"
-    jobs: "{{ nproc.stdout }}"
+    jobs: "{{ qemu_nproc.stdout }}"
   tags: ["qemu", "build"]
   when:
     - qemu_build_now|bool
 
 - name: Install QEMU
   become: true
-  become_flags: "su - -c"
-  become_method: sudo
+  become_method: ansible.builtin.sudo
   ansible.builtin.command: "{{ make }} install"
+  changed_when: true
   args:
     chdir: "{{ qemu_data }}"
   tags: ["qemu", "install"]

-- 
2.54.0