|
| 1 | +--- |
| 2 | + |
| 3 | +- name: "Ensure kernel headers are installed (yum)" |
| 4 | + yum: |
| 5 | + name: "{{ cuda_runfile_packages }}" |
| 6 | + state: present |
| 7 | + when: ansible_pkg_mgr in ["yum", "dnf"] |
| 8 | + |
| 9 | +- name: "Ensure kernel headers are installed (apt)" |
| 10 | + yum: |
| 11 | + name: |
| 12 | + - linux-headers-generic |
| 13 | + - build-essential |
| 14 | + state: present |
| 15 | + when: ansible_pkg_mgr == "apt" |
| 16 | + |
| 17 | +- name: "Disable nouveau" |
| 18 | + copy: |
| 19 | + src: blacklist-nouveau.conf |
| 20 | + dest: /etc/modprobe.d/blacklist-nouveau.conf |
| 21 | + |
| 22 | +- name: "Register installer name" |
| 23 | + set_fact: |
| 24 | + cuda_runfile_sh: "{{ cuda_runfile_url | basename }}" |
| 25 | + |
| 26 | +- name: "Determine running kernel" |
| 27 | + command: uname -r |
| 28 | + register: cuda_driver_kernel_running |
| 29 | + |
| 30 | +- name: "Determine kernel version" |
| 31 | + set_fact: |
| 32 | + cuda_driver_kernel_version: "{{ cuda_driver_kernel_version | default(cuda_driver_kernel_running.stdout, true) }}" |
| 33 | + |
| 34 | +- name: "Check NVIDIA kernel module" |
| 35 | + find: |
| 36 | + path: "/lib/modules/{{ cuda_driver_kernel_version }}" |
| 37 | + patterns: nvidia.ko |
| 38 | + recurse: true |
| 39 | + register: cuda_driver_kernel_module_find |
| 40 | + |
| 41 | +- name: "Check CUDA toolkit path" |
| 42 | + stat: |
| 43 | + path: /usr/local/cuda |
| 44 | + register: cuda_toolkit_path |
| 45 | + |
| 46 | +- name: "Determine if driver and toolkit are installed" |
| 47 | + set_fact: |
| 48 | + cuda_driver_installed: "{{ cuda_driver_kernel_module_find.matched > 0 }}" |
| 49 | + cuda_toolkit_installed: "{{ cuda_toolkit_path.stat.exists }}" |
| 50 | + |
| 51 | +- name: "Print information about installed features" |
| 52 | + debug: |
| 53 | + msg: |
| 54 | + - "Driver installed: {{ cuda_driver_installed }}" |
| 55 | + - "Toolkit installed: {{ cuda_toolkit_installed }}" |
| 56 | + |
| 57 | +- name: "Create temporary directory for runfile" |
| 58 | + file: |
| 59 | + path: /tmp/cuda_runfile |
| 60 | + state: directory |
| 61 | + |
| 62 | +- name: "Obtain runfile" |
| 63 | + block: |
| 64 | + |
| 65 | + - name: "Copy pre-downloaded runfile" |
| 66 | + copy: |
| 67 | + src: "{{ cuda_runfile_sh }}" |
| 68 | + dest: /tmp/cuda_runfile |
| 69 | + when: not cuda_runfile_download |
| 70 | + |
| 71 | + - name: "Download runfile" |
| 72 | + get_url: |
| 73 | + url: "{{ cuda_runfile_url }}" |
| 74 | + dest: "/tmp/cuda_runfile/{{ cuda_runfile_sh }}" |
| 75 | + when: cuda_runfile_download |
| 76 | + |
| 77 | + when: (cuda_runfile_toolkit and not cuda_toolkit_installed) or |
| 78 | + (cuda_runfile_driver and not cuda_driver_installed) |
| 79 | + |
| 80 | +- name: "Run installer for toolkit" |
| 81 | + command: bash /tmp/cuda_runfile/{{ cuda_runfile_sh }} --silent --toolkit |
| 82 | + register: cuda_toolkit_install_out |
| 83 | + when: cuda_runfile_toolkit and not cuda_toolkit_installed |
| 84 | + |
| 85 | +- name: "Install driver" |
| 86 | + block: |
| 87 | + |
| 88 | + - name: "Extract installer for driver installation" |
| 89 | + command: bash /tmp/cuda_runfile/{{ cuda_runfile_sh }} --extract=/tmp/cuda_runfile |
| 90 | + |
| 91 | + - name: "Find NVIDIA runtime" |
| 92 | + find: |
| 93 | + paths: /tmp/cuda_runfile |
| 94 | + patterns: "NVIDIA*.run" |
| 95 | + register: cuda_driver_runfile_find |
| 96 | + |
| 97 | + - name: "Set NVIDIA runfile path" |
| 98 | + set_fact: |
| 99 | + cuda_driver_runfile: "{{ cuda_driver_runfile_find.files[0].path }}" |
| 100 | + |
| 101 | + - name: "Print information about driver" |
| 102 | + debug: |
| 103 | + msg: "Building driver {{ cuda_driver_runfile }} for kernel {{ cuda_driver_kernel_version }}" |
| 104 | + |
| 105 | + - name: "Install driver" |
| 106 | + command: > |
| 107 | + bash {{ cuda_driver_runfile }} --silent |
| 108 | + --kernel-name={{ cuda_driver_kernel_version }} |
| 109 | + --kernel-source-path=/usr/src/kernels/{{ cuda_driver_kernel_version }} |
| 110 | + {{ "--no-drm" if cuda_runfile_disable_nvidia_drm else "" }} |
| 111 | +
|
| 112 | + - name: "Install nvidia-persistenced systemd-file" |
| 113 | + copy: |
| 114 | + src: files/nvidia-persistenced.service |
| 115 | + dest: /etc/systemd/system/nvidia-persistenced.service |
| 116 | + when: cuda_init_persistence_mode | bool |
| 117 | + |
| 118 | + when: cuda_runfile_driver and not cuda_driver_installed |
| 119 | + |
| 120 | +- name: "Remove installer" |
| 121 | + file: |
| 122 | + path: /tmp/cuda_runfile |
| 123 | + state: absent |
| 124 | + when: cuda_runfile_remove |
0 commit comments