Skip to content

Commit

Permalink
Merge pull request #24 from ajdecon/new-packages
Browse files Browse the repository at this point in the history
Ubuntu: Use NVIDIA server drivers from Canonical
  • Loading branch information
michael-balint authored Dec 15, 2020
2 parents 8a9f78e + 4502906 commit f04c440
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 26 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ $ ansible-galaxy install nvidia.nvidia_driver

### Ubuntu specific variables

For Ubuntu installs, you have the choice of installing from the Canonical repositories and the NVIDIA CUDA repositories.

By default, the Canonical repositories will be used, and the driver installed will be the headless server driver.

| Variable | Default value | Description |
| -------- | ------------- | ----------- |
| `nvidia_driver_ubuntu_install_from_cuda_repo` | `no` | Flag whether to use the CUDA repo |
| `nvidia_driver_ubuntu_branch` | `450` | Driver branch to use for the install |
| `nvidia_driver_ubuntu_packages` | `["nvidia-headless-450-server", "nvidia-headless-450-utils"]` | Package names to install from Canonical repo |
| `nvidia_driver_ubuntu_cuda_repo_baseurl` | `"http://developer.download.nvidia.com/compute/cuda/repos/{{ _ubuntu_repo_dir }}"` | Base URL to use for CUDA repo |
| `nvidia_driver_ubuntu_cuda_repo_gpgkey_url` | `"https://developer.download.nvidia.com/compute/cuda/repos/{{ _ubuntu_repo_dir }}/7fa2af80.pub"` | GPG key for the CUDA repo |
| `nvidia_driver_ubuntu_cuda_repo_gpgkey_id` | `"7fa2af80"` | GPG key ID for the CUDA repo |
| `nvidia_driver_ubuntu_cuda_package` | `"cuda-drivers"` | Package name to install from CUDA repo |

## Example playbook

Expand All @@ -64,6 +71,8 @@ $ ansible-galaxy install nvidia.nvidia_driver
Currently, this role supports the following Linux distributions:

* NVIDIA DGX OS 4
* NVIDIA DGX OS 5
* Ubuntu 18.04 LTS
* Ubuntu 20.04 LTS
* CentOS 7
* Red Hat Enterprise Linux 7
22 changes: 20 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@ nvidia_driver_skip_reboot: no
nvidia_driver_module_file: /etc/modprobe.d/nvidia.conf
nvidia_driver_module_params: ''

# RedHat family

##############################################################################
# RedHat family #
##############################################################################
nvidia_driver_rhel_cuda_repo_baseurl: "https://developer.download.nvidia.com/compute/cuda/repos/{{ _rhel_repo_dir }}/"
nvidia_driver_rhel_cuda_repo_gpgkey: "https://developer.download.nvidia.com/compute/cuda/repos/{{ _rhel_repo_dir }}/7fa2af80.pub"

# Ubuntu

##############################################################################
# Ubuntu #
##############################################################################

# Determine if we should install from CUDA repo instead of Canonical repos
nvidia_driver_ubuntu_install_from_cuda_repo: no

# Installing with Canonical repositories
nvidia_driver_ubuntu_branch: "450"
nvidia_driver_ubuntu_packages:
- "nvidia-headless-{{ nvidia_driver_ubuntu_branch }}-server"
- "nvidia-utils-{{ nvidia_driver_ubuntu_branch }}-server"

# Installing with CUDA repositories
nvidia_driver_ubuntu_cuda_repo_gpgkey_url: "https://developer.download.nvidia.com/compute/cuda/repos/{{ _ubuntu_repo_dir }}/7fa2af80.pub"
nvidia_driver_ubuntu_cuda_repo_gpgkey_id: "7fa2af80"
nvidia_driver_ubuntu_cuda_repo_baseurl: "http://developer.download.nvidia.com/compute/cuda/repos/{{ _ubuntu_repo_dir }}"
nvidia_driver_ubuntu_cuda_package: "cuda-drivers"
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ galaxy_info:
versions:
- 'xenial'
- 'bionic'
- 'focal'
- name: EL
versions:
- '7'
Expand Down
35 changes: 35 additions & 0 deletions tasks/install-ubuntu-cuda-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: remove ppa
apt_repository:
repo: ppa:graphics-drivers/ppa
state: absent

- name: add pin file
copy:
src: "cuda-ubuntu.pin"
dest: "/etc/apt/preferences.d/cuda-repository-pin-600"
owner: "root"
group: "root"
mode: "0644"

- name: add key
apt_key:
url: "{{ nvidia_driver_ubuntu_cuda_repo_gpgkey_url }}"
id: "{{ nvidia_driver_ubuntu_cuda_repo_gpgkey_id }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"


- name: add repo
apt_repository:
repo: "deb {{ nvidia_driver_ubuntu_cuda_repo_baseurl }} /"
update_cache: yes
environment: "{{proxy_env if proxy_env is defined else {}}}"

- name: install driver packages
apt:
name: "{{ nvidia_driver_package_version | ternary(nvidia_driver_ubuntu_cuda_package+'='+nvidia_driver_package_version, nvidia_driver_ubuntu_cuda_package) }}"
state: "{{ nvidia_driver_package_state }}"
autoremove: "{{ nvidia_driver_package_state == 'absent' }}"
purge: "{{ nvidia_driver_package_state == 'absent' }}"
register: install_driver
environment: "{{proxy_env if proxy_env is defined else {}}}"
24 changes: 2 additions & 22 deletions tasks/install-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,12 @@
repo: ppa:graphics-drivers/ppa
state: absent

- name: add pin file
copy:
src: "cuda-ubuntu.pin"
dest: "/etc/apt/preferences.d/cuda-repository-pin-600"
owner: "root"
group: "root"
mode: "0644"

- name: add key
apt_key:
url: "{{ nvidia_driver_ubuntu_cuda_repo_gpgkey_url }}"
id: "{{ nvidia_driver_ubuntu_cuda_repo_gpgkey_id }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"


- name: add repo
apt_repository:
repo: "deb {{ nvidia_driver_ubuntu_cuda_repo_baseurl }} /"
update_cache: yes
environment: "{{proxy_env if proxy_env is defined else {}}}"

- name: install driver packages
apt:
name: "{{ nvidia_driver_package_version | ternary('cuda-drivers='+nvidia_driver_package_version, 'cuda-drivers') }}"
name: "{{ nvidia_driver_package_version | ternary(item+'='+nvidia_driver_package_version, item) }}"
state: "{{ nvidia_driver_package_state }}"
autoremove: "{{ nvidia_driver_package_state == 'absent' }}"
purge: "{{ nvidia_driver_package_state == 'absent' }}"
with_items: "{{ nvidia_driver_ubuntu_packages }}"
register: install_driver
environment: "{{proxy_env if proxy_env is defined else {}}}"
8 changes: 6 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
state: absent
ignore_errors: true

- name: ubuntu install tasks
- name: ubuntu install tasks (canonical repos)
include_tasks: install-ubuntu.yml
when: ansible_distribution == 'Ubuntu'
when: ansible_distribution == 'Ubuntu' and (not nvidia_driver_ubuntu_install_from_cuda_repo)

- name: ubuntu install tasks (CUDA repo)
include_tasks: install-ubuntu-cuda-repo.yml
when: ansible_distribution == 'Ubuntu' and nvidia_driver_ubuntu_install_from_cuda_repo

- name: redhat family install tasks
include_tasks: install-redhat.yml
Expand Down

0 comments on commit f04c440

Please sign in to comment.