Skip to content

Commit 77cd5b9

Browse files
committed
initial role
0 parents  commit 77cd5b9

8 files changed

Lines changed: 144 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vscode
2+
venv
3+
env

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2026, virtUOS
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Ansible Role: nvidia_container_toolkit
2+
3+
Installs and configures the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/overview.html) for Docker on RPM-based systems.
4+
5+
## What it does
6+
7+
1. Adds the official NVIDIA Container Toolkit RPM repository.
8+
2. Installs the `nvidia-container-toolkit` package.
9+
3. Configures `/etc/docker/daemon.json` with the NVIDIA runtime.
10+
4. Restarts Docker when the daemon configuration changes.
11+
12+
## Requirements
13+
14+
- RPM-based OS (RHEL, Rocky, AlmaLinux, CentOS, Fedora)
15+
- Docker already installed
16+
- NVIDIA GPU drivers already installed on the host
17+
18+
## Role Variables
19+
20+
| Variable | Default | Description |
21+
|---|---|---|
22+
| `nvidia_container_toolkit_repo_url` | `https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo` | URL to the NVIDIA Container Toolkit RPM repository file. |
23+
| `nvidia_docker_default_runtime` | `nvidia` | The default container runtime for Docker. |
24+
25+
## Dependencies
26+
27+
- nvidia_driver_cuda
28+
- elan.docker_install
29+
30+
## Example Playbook
31+
32+
### Basic usage
33+
34+
```yaml
35+
- hosts: gpu_nodes
36+
roles:
37+
- nvidia_driver_cuda
38+
- elan.docker_install
39+
- nvidia_container_toolkit
40+
```
41+
42+
### With custom variables
43+
44+
```yaml
45+
- hosts: gpu_nodes
46+
roles:
47+
- role: nvidia_container_toolkit
48+
vars:
49+
nvidia_docker_default_runtime: "runc"
50+
```
51+
52+
## Handlers
53+
54+
- **Restart Docker:** Triggered when /etc/docker/daemon.json is modified.
55+
56+
## Important Notes
57+
58+
- This role overwrites /etc/docker/daemon.json. If you have existing Docker daemon configuration, merge it into the templates/daemon.json.j2 template.
59+
- This role does not install GPU drivers. Make sure drivers are present before running it.
60+
- This role only supports RPM-based distributions. For Debian/Ubuntu, the repository setup task needs to be adapted.

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
nvidia_container_toolkit_repo_url: "https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo"
3+
nvidia_docker_default_runtime: "nvidia"

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: Restart Docker
3+
ansible.builtin.systemd:
4+
name: docker
5+
state: restarted

meta/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
galaxy_info:
3+
role_name: nvidia_container_toolkit
4+
namespace: uos
5+
author: Timo Nogueira Brockmeyer
6+
description: Install nvidia container toolkit
7+
company: Osnabrück University
8+
license: BSD-3-Clause
9+
min_ansible_version: "0.1"
10+
dependencies:
11+
- elan.docker_install
12+
- nvidia_driver_cuda

tasks/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Add NVIDIA Container Toolkit repository
3+
ansible.builtin.get_url:
4+
url: "{{ nvidia_container_toolkit_repo_url }}"
5+
dest: /etc/yum.repos.d/nvidia-container-toolkit.repo
6+
mode: "0644"
7+
8+
- name: Install NVIDIA Container Toolkit
9+
ansible.builtin.package:
10+
name: nvidia-container-toolkit
11+
12+
- name: Create Docker daemon configuration directory
13+
ansible.builtin.file:
14+
path: /etc/docker
15+
state: directory
16+
mode: "0755"
17+
18+
- name: Configure Docker daemon with NVIDIA runtime support
19+
ansible.builtin.template:
20+
src: daemon.json.j2
21+
dest: /etc/docker/daemon.json
22+
mode: "0644"
23+
notify: Restart Docker

templates/daemon.json.j2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"default-runtime": "{{ nvidia_docker_default_runtime }}",
3+
"runtimes": {
4+
"nvidia": {
5+
"path": "nvidia-container-runtime",
6+
"runtimeArgs": []
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)