nvidia_desktop
This Role installs the latest Nvidia Driver on the target system.
General
This Role fullfills the following steps:
- Installs lshw for further hardware identication:
- name: Install LSHW application
apt:
name: lshw
state: present
become: true
- Determines if Nvidia GPU is installed in target system
- name: Determine if NVIDIA card is installed
shell: lshw -C display | grep "vendor"
register: gpu_vendor
- Stop execute the role if there is no Nvidia GPU installed:
- name: End Playbook if no NVIDIA card is installed
ansible.builtin.meta: end_play
when: "{{ 'NVIDIA' not in gpu_vendor.stdout}}"
- Check if Nvidia driver is already installed:
- name: Check if /proc/driver/nvidia exists
stat:
path: "/proc/driver/nvidia"
register: nvidia_path
when: "{{ 'NVIDIA' in gpu_vendor.stdout}}"
- Install specific Nvidia driver version (!!!Not Implemented at the moment!!!)
- name: Install specific nvidia driver
shell: "apt install nvidia-driver-{{ driver_version }}"
ignore_errors: true
register: install_driver
when: (not nvidia_path.stat.exists) and (driver_version != "autoinstall")
become: true
- Install recommendet Nvidia driver version (AutoInstall)
- name: Install recommended nvidia drivers
shell: |
ubuntu-drivers devices
ubuntu-drivers autoinstall
ignore_errors: true
register: auto_install_driver
when: (not nvidia_path.stat.exists) and (driver_version == "autoinstall")
become: true
- Restart device after installing the driver:
- name: restart device
shell: 'sleep 1 && shutdown -r now "Reboot triggered by Ansible" && sleep 1'
async: 1
poll: 0
when: (install_driver.changed) or (auto_install_driver.changed)
ignore_errors: true
- Wait for device to reconnect:
- name: Wait for client to restart
local_action:
module: wait_for
host={{ inventory_hostname }}
port=22
delay=10
when: (install_driver.changed) or (auto_install_driver.changed)
Dependencies
Role Dependencies
None
Package Dependencies
None
Role Variables
Name | Type | Default value | Purpose | Comment | Role |
---|---|---|---|---|---|
nvidia_driver_conf | Boolean | false | If this variable is set to true in the inventory file, Ansible will run the role | Possible values: true: enables role false: disables role |
nvidia_desktop |
driver_version | String | - | This variable defines if either the recommend or a specific driver version has to be installed | Possible values: autoinstall: Install recommended driver version 470: Install nvidia-driver-470 515: Install nvidia-driver-515 Can be done basically with every available driver version |
nvidia_desktop |
Example Playbook
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
---
- name: Install recommended NVIDIA Driver
hosts: all
roles:
- nvidia_desktop
Example Inventory/hosts
COMPUTERNAME:
nvidia_driver_conf: true
driver_version: autoinstall
License
BSD
Author Information
Maintainer:
Sandro Romagnoli
Support-Contact:
s4d-linux-support@id.ethz.ch