- name: Adicionar repositório Helm do nvida gpu
  command: >
    helm repo add nvidia https://nvidia.github.io/gpu-operator
  ignore_errors: yes
  
- name: Atualizar repositórios Helm
  command: helm repo update
  
- name: Instalar nvida gpu Driver via Helm
  command:  helm upgrade --install nvidia-operator nvidia/gpu-operator --namespace gpu-operator --create-namespace
  register: resultado_nvidia
  environment:
    KUBECONFIG:  /home/fenix/.kube/config

- name: Mostrar resultado do nvida gpu Driver
  debug:
    var: resultado_nvidia.stdout_lines


- name: Remover o diretório /tmp/nvidia/kubernetes-files
  ansible.builtin.file:
    path: /tmp/nvidia/kubernetes-files
    state: absent

- name: Criar diretório temporário no remoto
  file:
    path: /tmp/nvidia/kubernetes-files
    state: directory
    mode: '0755'

- name: Copy file with owner and permissions
  ansible.builtin.copy:
    src: ../files
    dest: /tmp/nvidia/kubernetes-files
    owner: fenix
    group: root
    mode: '0644'


- name: Listar conteúdo do diretório remoto
  shell: ls -l /tmp/nvidia/kubernetes-files/files
  register: resultado_ls


- name: Mostrar resultado do ls
  debug:
    var: resultado_ls.stdout_lines


- name: Aplicar o files
  become: yes
  become_user: fenix 
  shell: |
    kubectl apply -f /tmp/nvidia/kubernetes-files/files/
  environment:
    KUBECONFIG:  /home/fenix/.kube/config


- name: Aplicar o files
  become: yes
  become_user: fenix 
  shell: |
    kubectl patch clusterpolicies.nvidia.com/cluster-policy -n gpu-operator --type merge -p "{\"spec\": {\"devicePlugin\": {\"config\": {\"name\": \"time-slicing-config-all\", \"default\": \"any\"}}}}"
  environment:
    KUBECONFIG:  /home/fenix/.kube/config


