-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible_playbook_to_deploy_exo_pastel_code.yml
135 lines (122 loc) · 3.75 KB
/
ansible_playbook_to_deploy_exo_pastel_code.yml
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
52
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
- name: Update code and run Exo Python script in tmux
hosts: all
gather_facts: false
become: true
become_user: ubuntu
tasks:
- name: Determine the user shell
shell: echo $SHELL
register: user_shell
async: 600
poll: 10
ignore_errors: yes
- name: Set shell path and profile file
set_fact:
shell_path: "{{ user_shell.stdout }}"
profile_file: "{{ 'zshrc' if '/zsh' in user_shell.stdout else 'bashrc' }}"
ignore_errors: yes
- name: Check if exo_pastel directory exists
stat:
path: /home/ubuntu/exo_pastel
register: exo_dir
- name: Clone Exo repository if it doesn't exist
shell: |
git clone https://github.com/pastelnetwork/exo_pastel
args:
chdir: /home/ubuntu
executable: "{{ shell_path }}"
when: not exo_dir.stat.exists
async: 600
poll: 10
ignore_errors: yes
- name: Change to exo_pastel directory and set Python version with pyenv
shell: |
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv >/dev/null; then
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
fi
cd /home/ubuntu/exo_pastel
pyenv local 3.12
args:
executable: "{{ shell_path }}"
async: 600
poll: 10
ignore_errors: yes
- name: Pull latest code if exo_pastel directory exists
shell: |
git stash
git pull
args:
chdir: /home/ubuntu/exo_pastel
executable: "{{ shell_path }}"
when: exo_dir.stat.exists
async: 600
poll: 10
ignore_errors: yes
- name: Create temporary script for setting up and running Exo
copy:
content: |
#!/bin/{{ 'zsh' if '/zsh' in shell_path else 'bash' }}
source ~/.{{ profile_file }}
cd /home/ubuntu/exo_pastel
pyenv local 3.12
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install wheel
python -m pip install --upgrade setuptools wheel
pip install .
python main.py
dest: /home/ubuntu/run_exo.sh
mode: '0755'
retries: 3
delay: 60
ignore_errors: yes
- name: Get the name of the existing tmux session
shell: tmux list-sessions -F '#{session_name}' | head -1
register: tmux_session_name
ignore_errors: yes
async: 600
poll: 10
- name: Create tmux session if it doesn't exist
shell: tmux new-session -d -s default_session
when: tmux_session_name.stdout == ""
args:
executable: "{{ shell_path }}"
async: 600
poll: 10
ignore_errors: yes
- name: Set the tmux session name
set_fact:
session_name: "{{ tmux_session_name.stdout if tmux_session_name.stdout else 'default_session' }}"
ignore_errors: yes
- name: Check if exo window exists
shell: tmux list-windows -t {{ session_name }} -F '#{window_name}' | grep -q '^exo$'
register: exo_window_exists
ignore_errors: yes
async: 600
poll: 10
- name: Kill exo window if it exists
shell: tmux kill-window -t {{ session_name }}:exo
when: exo_window_exists.rc == 0
async: 600
poll: 10
ignore_errors: yes
- name: Launch Exo script in new tmux window
shell: |
tmux new-window -t {{ session_name }}: -n exo -d "{{ shell_path }} -c '/home/ubuntu/run_exo.sh'"
args:
executable: "{{ shell_path }}"
async: 600
poll: 10
ignore_errors: yes
- name: Remove temporary script
file:
path: /home/ubuntu/run_exo.sh
state: absent
retries: 3
delay: 60
ignore_errors: yes