#http://us.download.nvidia.com/XFree86/Linux-x86_64/367.35/NVIDIA-Linux-x86_64-367.35.run
- name: download nvidia {{nvidia_driver_version}} driver runfile
  get_url:
    url: "http://us.download.nvidia.com/XFree86/Linux-x86_64/{{nvidia_driver_version}}/NVIDIA-Linux-x86_64-{{nvidia_driver_version}}.run"
    dest: "/tmp/NVIDIA-Linux-x86_64-{{nvidia_driver_version}}.run"
    mode: 0700

- name: extract files from nvidia driver runfile
  shell: "/tmp/NVIDIA-Linux-x86_64-{{nvidia_driver_version}}.run -x"
  args:
    chdir: /tmp
    creates: /tmp/NVIDIA-Linux-x86_64-{{ nvidia_driver_version }}/README.txt

- name: copy cuda and related libs
  copy:
    src: /tmp/NVIDIA-Linux-x86_64-{{ nvidia_driver_version }}/{{ item }}.{{ nvidia_driver_version }}
    dest: /usr/lib/x86_64-linux-gnu/{{ item }}.{{ nvidia_driver_version }}
    owner: root
    group: root
    mode: 0755
    remote_src: yes
  with_items: "{{ libcuda_files }}"
  ignore_errors: yes

- name: create related symlinks
  file:
    src: /usr/lib/x86_64-linux-gnu/{{ item }}.{{ nvidia_driver_version }}
    dest: /usr/lib/x86_64-linux-gnu/{{ item }}
    owner: root
    group: root
    mode: 0755
    state: link
  with_items: "{{ libcuda_files }}"
  ignore_errors: yes

- name: create related symlinks
  file:
    src: /usr/lib/x86_64-linux-gnu/{{ item }}.{{ nvidia_driver_version }}
    dest: /usr/lib/x86_64-linux-gnu/{{ item }}.1
    owner: root
    group: root
    mode: 0755
    state: link
  with_items: "{{ libcuda_files }}"
  ignore_errors: yes
