|
17 | 17 | dest: "/etc/yum.repos.d/cuda-{{ cuda_distro }}.repo"
|
18 | 18 | url: "{{ cuda_repo }}"
|
19 | 19 |
|
| 20 | +- name: Check if nvidia driver module is enabled |
| 21 | + shell: |
| 22 | + cmd: dnf module list --enabled nvidia-driver |
| 23 | + changed_when: false |
| 24 | + failed_when: false |
| 25 | + register: _cuda_driver_module_enabled |
| 26 | + |
| 27 | +- name: List nvidia driver dnf module stream versions |
| 28 | + shell: |
| 29 | + cmd: dnf module list nvidia-driver | grep -oP "\d+-dkms" | sort -V |
| 30 | + # Output of interest from command is something like (some whitespace removed): |
| 31 | + # "nvidia-driver 418-dkms default [d], fm, ks Nvidia driver for 418-dkms branch " |
| 32 | + changed_when: false |
| 33 | + register: _cuda_driver_module_streams |
| 34 | + when: "'No matching Modules to list' in _cuda_driver_module_enabled.stderr" |
| 35 | + |
20 | 36 | - name: Enable nvidia driver module
|
21 |
| - ansible.builtin.command: dnf module enable -y nvidia-driver:latest-dkms |
22 |
| - register: nvidiadriver_enable |
23 |
| - changed_when: "'Nothing to do' not in nvidiadriver_enable.stdout" |
| 37 | + ansible.builtin.command: "dnf module enable -y nvidia-driver:{{ _cuda_driver_module_streams.stdout_lines | last }}" |
| 38 | + register: _cuda_driver_module_enable |
| 39 | + when: "'No matching Modules to list' in _cuda_driver_module_enabled.stderr" |
| 40 | + changed_when: "'Nothing to do' not in _cuda_driver_module_enable.stdout" |
24 | 41 |
|
25 |
| -- name: Install nvidia driver module |
26 |
| - ansible.builtin.command: dnf module install -y nvidia-driver:latest-dkms |
27 |
| - register: nvidiadriver_install |
28 |
| - changed_when: "'Nothing to do' not in nvidiadriver_install.stdout" |
| 42 | +- name: Install nvidia drivers # TODO: make removal possible? |
| 43 | + ansible.builtin.command: dnf module install -y nvidia-driver |
| 44 | + register: _cuda_driver_install |
| 45 | + when: "'No matching Modules to list' in _cuda_driver_module_enabled.stderr" |
| 46 | + changed_when: "'Nothing to do' not in _cuda_driver_install.stdout" |
29 | 47 |
|
30 | 48 | - name: Install cuda packages
|
31 | 49 | ansible.builtin.dnf:
|
32 | 50 | name: "{{ cuda_packages }}"
|
33 | 51 | register: cuda_package_install
|
34 | 52 |
|
35 |
| -- name: Add latest cuda binaries to path |
| 53 | +- name: Add cuda binaries to path |
36 | 54 | lineinfile:
|
37 | 55 | path: /etc/profile.d/sh.local
|
38 | 56 | line: 'export PATH=$PATH:$(ls -1d /usr/local/cuda-* | sort -V | tail -1)/bin'
|
|
0 commit comments