deploy.yaml 4.58 KB
Newer Older
1
2
3
4
5
6
- name: Facts Gathering
  hosts: all
  gather_facts: true

- name: Context Preparation
  hosts: localhost
7
  connection: local
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  gather_facts: false
  tasks:
    - name: Generating SSH Config
      template:
        src: ../templates/ssh_config.j2
        dest: '{{ output_dir }}/ssh_config'
        mode: 0640
    - name: Generating SSH Key Pair
      community.crypto.openssh_keypair:
        path: '{{ output_dir }}/id_ed25519'
        type: ed25519
        comment: superbench
        force: no

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
- name: Check GPU Environment
  hosts: all
  gather_facts: false
  tasks:
    - name: Checking NVIDIA GPU Environment
      stat:
        path: '{{ item }}'
      with_items:
        - /dev/nvidiactl
        - /dev/nvidia-uvm
      register: nvidia_dev
    - name: Checking AMD GPU Environment
      stat:
        path: '{{ item }}'
      with_items:
        - /dev/kfd
        - /dev/dri
      register: amd_dev
40
41
42
43
44
45
46
    - name: Checking HYGON GPU Environment
      stat:
        path: '{{ item }}'
      with_items:
        - /dev/kfd
        - /dev/dri
        - /usr/local/hyhal
one's avatar
one committed
47
        - /opt/hyhal
48
      register: hygon_dev
49
50
51
52
53
54
55
56
    - name: Set GPU Facts
      set_fact:
        nvidia_gpu_exist: >-
          {{ nvidia_dev.results[0].stat.ischr is defined and nvidia_dev.results[0].stat.ischr and
          nvidia_dev.results[1].stat.ischr is defined and nvidia_dev.results[1].stat.ischr }}
        amd_gpu_exist: >-
          {{ amd_dev.results[0].stat.ischr is defined and amd_dev.results[0].stat.ischr and
          amd_dev.results[1].stat.isdir is defined and amd_dev.results[1].stat.isdir }}
57
58
59
        hygon_gpu_exist: >-
          {{ (hygon_dev.results[0].stat.ischr is defined and hygon_dev.results[0].stat.ischr and
          hygon_dev.results[1].stat.isdir is defined and hygon_dev.results[1].stat.isdir) and
one's avatar
one committed
60
61
          ((hygon_dev.results[2].stat.exists is defined and hygon_dev.results[2].stat.exists) or
          (hygon_dev.results[3].stat.exists is defined and hygon_dev.results[3].stat.exists)) }}
62
63
64
    - name: Print GPU Checking Result
      debug:
        msg:
65
          - "NVIDIA GPU {{ 'detected' if nvidia_gpu_exist else 'not operational, pls confirm nvidia_uvm kernel module is loaded and /dev/nvidia-uvm exists' }}"
66
67
          - "AMD GPU {{ 'detected' if amd_gpu_exist and not hygon_gpu_exist else 'not operational, pls confirm amdgpu kernel module is loaded' }}"
          - "HYGON GPU {{ 'detected' if hygon_gpu_exist else 'not operational, pls confirm hygon gpu kernel module and driver are loaded' }}"
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
- name: Remote Deployment
  hosts: all
  gather_facts: false
  vars:
    workspace: '{{ ansible_user_dir }}/sb-workspace'
    container: sb-workspace
  tasks:
    - name: Creating Workspace
      file:
        path: '{{ item }}'
        state: directory
        mode: 0755
      with_items:
        - '{{ workspace }}'
        - '{{ workspace }}/.ssh'
    - name: Copying Context
      copy:
        src: '{{ item.src }}'
        dest: '{{ item.dest }}'
        mode: '{{ item.mode }}'
      with_items:
        - src: '{{ output_dir }}/ssh_config'
          dest: '{{ workspace }}/.ssh/config'
          mode: '644'
        - src: '{{ output_dir }}/id_ed25519.pub'
          dest: '{{ workspace }}/.ssh/authorized_keys'
          mode: '644'
        - src: '{{ output_dir }}/id_ed25519'
          dest: '{{ workspace }}/.ssh/key'
          mode: '400'
      become: yes
    - name: Trying to Login Registry
      shell: |
        docker login {{ docker_registry }} --username {{ docker_username }} --password {{ docker_password }}
      become: yes
      when: docker_registry is defined
      ignore_errors: true
    - name: Pulling Container Image
      shell: |
        docker pull {{ docker_image }}
      become: yes
110
      when: docker_pull | default(true)
111
      throttle: 32
112
113
114
115
    - name: Starting Container
      shell: |
        docker rm --force {{ container }} ||: && \
        docker run -itd --name={{ container }} \
116
          --privileged --net=host --ipc=host \
117
          {{ '--gpus=all' if nvidia_gpu_exist else '' }} \
118
          {{ '--security-opt seccomp=unconfined --group-add video --device=/dev/kfd --device=/dev/dri --cap-add=SYS_PTRACE --shm-size=16G' if amd_gpu_exist else '' }} \
one's avatar
one committed
119
          {{ '-v /opt/hyhal:/opt/hyhal:ro' if hygon_gpu_exist else '' }} \
120
          -w /root -v {{ workspace }}:/root -v /mnt:/mnt \
121
          -v /var/run/docker.sock:/var/run/docker.sock \
122
          --entrypoint /bin/bash {{ docker_image }} && \
123
124
125
126
127
        docker exec {{ container }} bash -c \
          "chown -R root:root ~ && \
          sed -i 's/[# ]*Port.*/Port {{ ssh_port }}/g' /etc/ssh/sshd_config && \
          service ssh restart && sb help"
      become: yes