97 lines
2.6 KiB
YAML
97 lines
2.6 KiB
YAML
---
|
|
# Docker CE + NVIDIA Container Toolkit
|
|
- name: Add Docker GPG key
|
|
apt_key:
|
|
url: https://download.docker.com/linux/ubuntu/gpg
|
|
state: present
|
|
|
|
- name: Add Docker apt repository
|
|
apt_repository:
|
|
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
|
|
state: present
|
|
filename: docker
|
|
|
|
- name: Install Docker CE
|
|
apt:
|
|
name:
|
|
- docker-ce
|
|
- docker-ce-cli
|
|
- containerd.io
|
|
- docker-buildx-plugin
|
|
- docker-compose-plugin
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: Add cezen user to docker group
|
|
user:
|
|
name: cezen
|
|
groups: docker
|
|
append: yes
|
|
|
|
- name: Enable and start Docker
|
|
systemd:
|
|
name: docker
|
|
enabled: yes
|
|
state: started
|
|
|
|
- name: Configure Docker standard runtime for non-GPU installs
|
|
copy:
|
|
dest: /etc/docker/daemon.json
|
|
content: |
|
|
{
|
|
"log-driver": "json-file",
|
|
"log-opts": {
|
|
"max-size": "100m",
|
|
"max-file": "3"
|
|
}
|
|
}
|
|
mode: "0644"
|
|
notify: restart docker
|
|
when: not (gpu_available | default(false) | bool)
|
|
|
|
# NVIDIA Container Toolkit (allows GPU passthrough into containers)
|
|
- name: Add NVIDIA Container Toolkit repo
|
|
shell: |
|
|
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \
|
|
gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
|
|
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
|
|
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
|
|
tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
|
|
args:
|
|
creates: /etc/apt/sources.list.d/nvidia-container-toolkit.list
|
|
when: gpu_available | default(false) | bool
|
|
|
|
- name: Install NVIDIA Container Toolkit
|
|
apt:
|
|
name: nvidia-container-toolkit
|
|
state: present
|
|
update_cache: yes
|
|
when: gpu_available | default(false) | bool
|
|
|
|
- name: Configure Docker to use NVIDIA runtime
|
|
shell: nvidia-ctk runtime configure --runtime=docker
|
|
notify: restart docker
|
|
when: gpu_available | default(false) | bool
|
|
|
|
- name: Set NVIDIA as default Docker runtime
|
|
copy:
|
|
dest: /etc/docker/daemon.json
|
|
content: |
|
|
{
|
|
"default-runtime": "nvidia",
|
|
"runtimes": {
|
|
"nvidia": {
|
|
"path": "nvidia-container-runtime",
|
|
"runtimeArgs": []
|
|
}
|
|
},
|
|
"log-driver": "json-file",
|
|
"log-opts": {
|
|
"max-size": "100m",
|
|
"max-file": "3"
|
|
}
|
|
}
|
|
mode: "0644"
|
|
notify: restart docker
|
|
when: gpu_available | default(false) | bool
|