fix(nvidia_drivers): scope cleanup to real verify failures, spare version mismatch

Replace the block/rescue that caught any error -- including templating errors in
the debug task -- with explicit conditional cleanup gated on nvidia-smi's actual
return code. A cosmetic failure can no longer roll back a working install. rc 18
(driver/library version mismatch) now fails with guidance and leaves packages intact.
This commit is contained in:
2026-07-27 16:54:41 -04:00
parent b212092db1
commit 068f001412
+43 -15
View File
@@ -75,28 +75,42 @@
state: present
when: nvidia_optional_packages | length > 0
- name: Verify and handle NVIDIA driver installation
block:
- name: Verify NVIDIA driver installation
# Capture the verification result without failing the play here, so that only a
# genuine driver failure (evaluated explicitly below) can trigger the destructive
# package cleanup. A cosmetic/templating error in a later task can no longer roll
# back a working install.
- name: Verify NVIDIA driver installation
ansible.builtin.command:
cmd: nvidia-smi
register: nvidia_verification
changed_when: false
failed_when: false
when: kernel_driver_install is changed or cuda_driver_install is changed
- name: Display NVIDIA driver information
ansible.builtin.debug:
# rc 18 = "Driver/library version mismatch": the driver is installed correctly but
# the running kernel module differs from userspace. This needs a reboot (kernel-module
# installs) or aligning the container driver to the Proxmox host version (LXC) -- it is
# NOT a broken install, so leave the packages in place.
- name: Fail on driver/library version mismatch (packages left intact)
ansible.builtin.fail:
msg: >-
{{
nvidia_verification.stdout_lines
if (nvidia_verification.rc is defined and nvidia_verification.rc == 0)
else nvidia_check.stdout_lines
}}
when: >-
(nvidia_verification.rc is defined and nvidia_verification.rc == 0)
or nvidia_check.rc == 0
nvidia-smi reports a driver/library version mismatch (rc 18). The driver is
installed but the running kernel module version differs from userspace. Reboot
the host for kernel-module installs, or align this container's NVIDIA userspace
driver to the Proxmox host's kernel driver version (LXC), then re-run. Packages
were left in place.
when:
- nvidia_verification.rc is defined
- nvidia_verification.rc == 18
rescue:
# Only a real verification failure (nvidia-smi ran and returned non-zero, excluding the
# version-mismatch case above) rolls back the install.
- name: Clean up failed NVIDIA driver installation
when:
- nvidia_verification.rc is defined
- nvidia_verification.rc != 0
- nvidia_verification.rc != 18
block:
- name: Remove partially installed packages on failure
ansible.builtin.apt:
name:
@@ -113,4 +127,18 @@
- name: Fail with helpful message
ansible.builtin.fail:
msg: "NVIDIA driver installation failed. Packages have been cleaned up."
msg: >-
NVIDIA driver verification failed (nvidia-smi rc={{ nvidia_verification.rc }}).
Packages have been cleaned up. Output: {{ nvidia_verification.stdout | default('') }}
- name: Display NVIDIA driver information
ansible.builtin.debug:
msg: >-
{{
nvidia_verification.stdout_lines
if (nvidia_verification.rc is defined and nvidia_verification.rc == 0)
else nvidia_check.stdout_lines
}}
when: >-
(nvidia_verification.rc is defined and nvidia_verification.rc == 0)
or nvidia_check.rc == 0