- name: nvidia apt key
  become: true
  apt_key:
    url: 'https://nvidia.github.io/nvidia-container-runtime/gpgkey'
- name: set distribution string
  set_fact:
    container_runtime_distribution_string: '{{ ansible_distribution | lower }}{{ ansible_distribution_version }}'
  when: ansible_distribution_release != 'focal'
- name: set distribution string for Ubuntu 20
  set_fact:
    container_runtime_distribution_string: 'ubuntu18.04'
  when: ansible_distribution_release == 'focal'
- name: container runtime apt repo
  become: true
  apt_repository:
    repo: 'deb https://nvidia.github.io/{{item}}/stable/{{container_runtime_distribution_string}}/$(ARCH) /'
    filename: nvidia-container-runtime
  with_items:
    - nvidia-container-runtime
    - libnvidia-container
- name: install nvidia and related packages
  become: true
  apt:
    update_cache: true
    name: 'nvidia-driver-{{ nvidia_driver_version }},nvidia-cuda-dev,nvidia-cuda-doc,nvidia-cuda-gdb,nvidia-cuda-toolkit,nvidia-cuda-toolkit-gcc,nvidia-container-runtime'
- name: check install of cudnn
  find:
    paths:
      - /usr/lib/x86_64-linux-gnu
    patterns: 'libcudnn.so.7*'
  register: cudnn_result
- name: install cudnn
  become: true
  apt:
    deb: 'https://minio.mycard.moe:9000/nanahira/cudnn/{{item}}.deb'
  with_items:
    - libcudnn7_7.6.5.32-1+cuda10.1_amd64
    - libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64
    - libcudnn7-doc_7.6.5.32-1+cuda10.1_amd64
  when: not cudnn_result.files[0] is defined and ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int >= 18
