summaryrefslogtreecommitdiffstats
path: root/roles/cuda/tasks/cuda_init.yml
blob: 9a10284b442d7d7b7e1537a28e5028d28d8e156c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
- name: template in cuda_init.sh used during boot
  template:
    src: cuda_init.sh.j2
    dest: /usr/local/bin/cuda_init.sh
    mode: 0755
  notify:
    - Initialize the GPUs

- name: lineinfile/make sure cuda_init.sh script is absent from rc.local
  lineinfile:
    dest: /etc/rc.local
    insertafter: "^touch /var/lock/subsys/local"
    regexp: "^/bin/bash /usr/local/bin/cuda_init.sh$"
    line: "/bin/bash /usr/local/bin/cuda_init.sh"
    state: absent

- name: template in cuda_init.service systemd script
  template:
    src: cuda_init.service.j2
    dest: /etc/systemd/system/cuda_init.service
    mode: 0644
  notify:
    - reload systemd unit files
    - Restart cuda_init service
  when: ansible_service_mgr == "systemd"

- name: enable the cuda_init systemd service
  service:
    name: cuda_init
    enabled: yes
  when: ansible_service_mgr == "systemd"

- name: check if cuda_gpu_name0 ( /dev/nvidia0 ) exists
  stat:
    path: "{{ cuda_gpu_name0 }}"
  register: reg_cuda_gpu_name0
  check_mode: no

- debug:
    var: reg_cuda_gpu_name0
    verbosity: 1

- name: Initialize the GPUs  - run cuda_init.sh if there is no /dev/nvidia0 
  command: /bin/bash /usr/local/bin/cuda_init.sh
  when:
    - reg_cuda_gpu_name0.stat.exists is defined
    - reg_cuda_gpu_name0.stat.exists == False
    - cuda_init_restart_service

# vim:ft=ansible: