diff --git a/defaults/main.yml b/defaults/main.yml index 197aa8d..5cf6731 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,6 +19,33 @@ nvidia_driver_rhel_cuda_repo_gpgkey: "https://developer.download.nvidia.com/comp nvidia_driver_rhel_branch: "{{ nvidia_driver_branch }}" +############################################################################## +# Debian +############################################################################## + +# Driver branch to install with Debian +nvidia_driver_debian_branch: "{{ nvidia_driver_branch }}" + +# Determine if we should install from CUDA repo instead of Canonical repos +nvidia_driver_debian_install_from_cuda_repo: no + +# Installing with Debian repositories +nvidia_driver_debian_packages: +- "nvidia-driver" +- "nvidia-cuda-dev" +- "nvidia-cuda-toolkit" + +nvidia_driver_debian_install_tesla_driver: no +nvidia_driver_debian_tesla_package: "nvidia-tesla-470-driver" + +# Installing with CUDA repositories +old_nvidia_driver_debian_cuda_repo_gpgkey_id: "7fa2af80" +nvidia_driver_debian_cuda_repo_baseurl: "https://developer.download.nvidia.com/compute/cuda/repos/{{ _debian_repo_dir }}" +nvidia_driver_debian_cuda_keyring_package: "cuda-keyring_1.1-1_all.deb" +nvidia_driver_debian_cuda_keyring_url: "{{ nvidia_driver_debian_cuda_repo_baseurl }}/{{ nvidia_driver_debian_cuda_keyring_package }}" +nvidia_driver_debian_cuda_package: "cuda-drivers-{{ nvidia_driver_debian_branch }}" + + ############################################################################## # Ubuntu # ############################################################################## diff --git a/tasks/install-debian-cuda-repo.yml b/tasks/install-debian-cuda-repo.yml new file mode 100644 index 0000000..1158b6b --- /dev/null +++ b/tasks/install-debian-cuda-repo.yml @@ -0,0 +1,50 @@ +- name: add contrib & non-free repository + replace: + dest: /etc/apt/sources.list + regexp: '^(deb(?!.* contrib).*)' + replace: '\1 contrib non-free' + +- name: remove old signing key + apt_key: + id: "{{ old_nvidia_driver_debian_cuda_repo_gpgkey_id }}" + state: absent + environment: "{{proxy_env if proxy_env is defined else {}}}" + when: nvidia_driver_add_repos | bool + +- name: add CUDA keyring + apt: + deb: "{{ nvidia_driver_debian_cuda_keyring_url }}" + state: "present" + environment: "{{proxy_env if proxy_env is defined else {}}}" + when: nvidia_driver_add_repos | bool + +- name: force an apt update + apt: + update_cache: true + changed_when: false + +- name: ensure kmod is installed + apt: + name: "kmod" + state: "present" + +- name: blacklist nouveau + kernel_blacklist: + name: nouveau + state: present + +- name: install Linux headers and non-free firmware + apt: + name: + - linux-headers-{{ ansible_kernel }} + - firmware-misc-nonfree + state: present + +- name: install driver packages + apt: + name: "{{ nvidia_driver_package_version | ternary(nvidia_driver_debian_cuda_package+'='+nvidia_driver_package_version, nvidia_driver_debian_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 {}}}" diff --git a/tasks/install-debian.yml b/tasks/install-debian.yml new file mode 100644 index 0000000..efa55f1 --- /dev/null +++ b/tasks/install-debian.yml @@ -0,0 +1,35 @@ +--- +- name: add contrib & non-free repository + replace: + dest: /etc/apt/sources.list + regexp: '^(deb(?!.* contrib).*)' + replace: '\1 contrib non-free' + +- name: update apt + become: yes + apt: + update_cache: yes + +- name: install Linux headers and non-free firmware + apt: + name: + - linux-headers-{{ ansible_kernel }} + - firmware-misc-nonfree + state: present + +- name: install driver packages + apt: + 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' }}" + loop: "{{ nvidia_driver_debian_packages }}" + register: install_driver + environment: "{{proxy_env if proxy_env is defined else {}}}" + +- name: install tesla drivers + apt: + state: present + name: "{{ nvidia_driver_debian_tesla_package }}" + register: install_driver + when: nvidia_driver_debian_install_tesla_driver == true diff --git a/tasks/main.yml b/tasks/main.yml index d33f672..3c5c340 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,6 +5,14 @@ state: absent ignore_errors: true +- name: debian install tasks (debian repos) + include_tasks: install-debian.yml + when: ansible_distribution == "Debian" and (not nvidia_driver_debian_install_from_cuda_repo) + +- name: debian install tasks (CUDA repos) + include_tasks: install-debian.yml + when: ansible_distribution == "Debian" and nvidia_driver_debian_install_from_cuda_repo + - name: ubuntu install tasks (canonical repos) include_tasks: install-ubuntu.yml when: ansible_distribution == 'Ubuntu' and (not nvidia_driver_ubuntu_install_from_cuda_repo) diff --git a/vars/main.yml b/vars/main.yml index c994f5b..8b1ae49 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,3 @@ +_debian_repo_dir: "{{ ansible_distribution | lower }}{{ ansible_distribution_version | replace('.', '') }}/{{ ansible_architecture }}" _ubuntu_repo_dir: "{{ ansible_distribution | lower }}{{ ansible_distribution_version | replace('.', '') }}/{{ ansible_architecture }}" _rhel_repo_dir: "rhel{{ ansible_distribution_major_version }}/{{ ansible_architecture }}"