- block:

  # The following dependencies are need to install the XDMA driver
  - name: Install XDMA driver dependencies
    apt:
      name:
        - "dkms"
      install_recommends: no
      cache_valid_time: "{{ apt_cache_valid_time }}"

  - name: Create stub directory
    file:
      path: /stubs
      state: directory
    when: not is_live_update

  - name: Create stubs for modprobe and rmmod
    file:
      path: "/stubs/{{ item }}"
      state: link
      src: "/bin/true"
    with_items:
      - modprobe
      - rmmod
    when: not is_live_update

  - include_vars:
      file: "../roles/nvidia/vars/main.yml"

  - name: Install XDMA Driver
    http_deb:
      name: xdma
      version: "{{ xdma_version }}"
      url: "{{ xdma_download_url }}"
      checksum: "sha256:{{ xdma_sha }}"
    environment:
      # Make modprobe and rmmod resolve to /bin/true
      PATH: "/stubs:{{ ansible_env.PATH }}"
      NVIDIA_VERSION_STRING_DEFAULT: "{{ nvidia_version }}"

  - name: Remove stubs directory
    file:
      path: /stubs
      state: absent
    when: not is_live_update

  become: yes
