deploy.yaml 2.35 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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  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

- 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
    - name: Starting Container
      shell: |
        docker rm --force {{ container }} ||: && \
        docker run -itd --name={{ container }} \
67
          --privileged --net=host --ipc=host \
68
69
          {{ '--gpus=all' if gpu_vendor == 'nvidia' else '' }} \
          {{ '--security-opt seccomp=unconfined --group-add video' if gpu_vendor == 'amd' else '' }} \
70
71
72
73
74
75
76
          -w /root -v {{ workspace }}:/root -v /mnt:/mnt \
          {{ docker_image }} bash && \
        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