#  Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

---
- name: install Nvidia driver
  yum:
    name:
      - kmod-nvidia
      #- nvidia-x11-drv
    state: present
  tags: install

#- name: add Nvidia container runtime support
  #get_url:
    #url: https://nvidia.github.io/nvidia-docker/centos7/nvidia-docker.repo
    #dest: /etc/yum.repos.d/nvidia-docker.repo
  #tags: install

- name: add Nvidia container runtime support
  get_url:
    url: https://nvidia.github.io/nvidia-container-runtime/centos7/nvidia-container-runtime.repo
    dest: /etc/yum.repos.d/nvidia-container-runtime.repo
  tags: install, testing

# disable gpg key (because Nvidia doesn't know how to make that work yet for some reason)
- replace:
    path: /etc/yum.repos.d/nvidia-container-runtime.repo
    regexp: 'repo_gpgcheck=1'
    replace: 'repo_gpgcheck=0'
    backup: yes
  tags: testing

- name: install Nvidia-container-runtime-hook
  yum:
    name:
      #- nvidia-detect
      #- kmod-nvidia-410.73-1.el7_5.elrepo
      - nvidia-container-runtime-hook
    state: present
  tags: install


# This needs to be done on GPU nodes
#- name: Enable DevicePlugins for all GPU nodes (nvidia-container-runtime-hook)
  #copy: src=nvidia dest=/usr/libexec/oci/hooks.d/ owner=root group=root mode=755
  #tags: install

#- name: Add KUBE_EXTRA_ARGS to enable Plugins (GPU support)  --III alreday done in common
  #lineinfile:
    #path: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
    #line: 'Environment="KUBELET_EXTRA_ARGS=--feature-gates=DevicePlugins=true"'
    #insertbefore: 'KUBELET_KUBECONFIG_ARGS='
  #tags: install

- name: Restart and Enable docker service
  service:
    name: docker
    state: restarted
    enabled: yes
  tags: install

- name: Restart and Enable Kubernetes - kubelet
  service:
    name: kubelet
    state: restarted
    enabled: yes
  tags: install