- name: Instalar driver NVIDIA
  become: yes
  ansible.builtin.apt:
    name: nvidia-driver-550
    state: present

- name: Instalar utilitários NVIDIA
  become: yes
  ansible.builtin.apt:
    name: nvidia-utils-550
    state: present


- name: Reboot host e esperar voltar
  become: yes
  ansible.builtin.reboot:
    reboot_timeout: 600   # tempo máximo para o host voltar (segundos)
    test_command: whoami  # comando usado para validar que o host voltou

- name: Adicionar chave GPG da NVIDIA
  become: yes
  become_user: fenix 
  ansible.builtin.shell: |
    curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit.gpg
  args:
    creates: /usr/share/keyrings/nvidia-container-toolkit.gpg

- name: Adicionar repositório NVIDIA
  become: yes
  ansible.builtin.shell: |
    curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo 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' | \
        sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
  args:
    creates: /etc/apt/sources.list.d/nvidia-container-toolkit.list

- name: Atualizar cache de pacotes
  become: yes
  ansible.builtin.apt:
    update_cache: yes

- name: Instalar NVIDIA Container Toolkit
  become: yes
  ansible.builtin.apt:
    name: nvidia-container-toolkit
    state: present


- name: Configurar runtime containerd
  become: yes
  ansible.builtin.shell: |
    nvidia-ctk runtime configure --runtime=containerd

- name: Reiniciar containerd
  become: yes
  ansible.builtin.systemd:
    name: containerd
    state: restarted


- name: Mostrar resultado nvidia-smi
  become: yes
  ansible.builtin.debug:
    var: nvidia_smi_output.stdout

