deploy.yaml 3.67 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
40
41
42
43
44
45
46
47
48
49
50
- 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
    - 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 }}
    - name: Print GPU Checking Result
      debug:
        msg:
51
52
          - "NVIDIA GPU {{ 'detected' if nvidia_gpu_exist else 'not operational, pls confirm nvidia_uvm kernel module is loaded and /dev/nvidia-uvm exists' }}"
          - "AMD GPU {{ 'detected' if amd_gpu_exist else 'not operational, pls confirm amdgpu kernel module is loaded' }}"
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
- 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
95
      when: docker_pull | default(true)
96
      throttle: 32
97
98
99
100
    - name: Starting Container
      shell: |
        docker rm --force {{ container }} ||: && \
        docker run -itd --name={{ container }} \
101
          --privileged --net=host --ipc=host \
102
103
          {{ '--gpus=all' if nvidia_gpu_exist else '' }} \
          {{ '--security-opt seccomp=unconfined --group-add video' if amd_gpu_exist else '' }} \
104
          -w /root -v {{ workspace }}:/root -v /mnt:/mnt \
105
          -v /var/run/docker.sock:/var/run/docker.sock \
106
          --entrypoint /bin/bash {{ docker_image }} && \
107
108
109
110
111
        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