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:
@@ -75,28 +75,42 @@
|
|||||||
state: present
|
state: present
|
||||||
when: nvidia_optional_packages | length > 0
|
when: nvidia_optional_packages | length > 0
|
||||||
|
|
||||||
- name: Verify and handle NVIDIA driver installation
|
# Capture the verification result without failing the play here, so that only a
|
||||||
block:
|
# genuine driver failure (evaluated explicitly below) can trigger the destructive
|
||||||
- name: Verify NVIDIA driver installation
|
# 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:
|
ansible.builtin.command:
|
||||||
cmd: nvidia-smi
|
cmd: nvidia-smi
|
||||||
register: nvidia_verification
|
register: nvidia_verification
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
when: kernel_driver_install is changed or cuda_driver_install is changed
|
when: kernel_driver_install is changed or cuda_driver_install is changed
|
||||||
|
|
||||||
- name: Display NVIDIA driver information
|
# rc 18 = "Driver/library version mismatch": the driver is installed correctly but
|
||||||
ansible.builtin.debug:
|
# 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: >-
|
msg: >-
|
||||||
{{
|
nvidia-smi reports a driver/library version mismatch (rc 18). The driver is
|
||||||
nvidia_verification.stdout_lines
|
installed but the running kernel module version differs from userspace. Reboot
|
||||||
if (nvidia_verification.rc is defined and nvidia_verification.rc == 0)
|
the host for kernel-module installs, or align this container's NVIDIA userspace
|
||||||
else nvidia_check.stdout_lines
|
driver to the Proxmox host's kernel driver version (LXC), then re-run. Packages
|
||||||
}}
|
were left in place.
|
||||||
when: >-
|
when:
|
||||||
(nvidia_verification.rc is defined and nvidia_verification.rc == 0)
|
- nvidia_verification.rc is defined
|
||||||
or nvidia_check.rc == 0
|
- 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
|
- name: Remove partially installed packages on failure
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
@@ -113,4 +127,18 @@
|
|||||||
|
|
||||||
- name: Fail with helpful message
|
- name: Fail with helpful message
|
||||||
ansible.builtin.fail:
|
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
|
||||||
Reference in New Issue
Block a user