-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaleo_node.yml
196 lines (171 loc) · 5.87 KB
/
aleo_node.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
---
- name: Manage an Aleo testnet node
hosts: localhost
become: true
vars_prompt:
- name: node_action
prompt: "Enter the action to perform (install, update, remove)"
private: false
tasks:
- name: Check if running as root
ansible.builtin.command: id -u
register: uid
changed_when: false
ignore_errors: true
check_mode: false
- name: Fail if not running as root
ansible.builtin.fail:
msg: "This playbook must be run as root."
when: uid.stdout != "0"
- name: Create Aleo directory
ansible.builtin.file:
path: /root/aleo
state: directory
mode: '0777' # Set permissions to 777
when: node_action == "install"
- name: Install dependencies
ansible.builtin.apt:
name:
- make
- clang
- pkg-config
- libssl-dev
- build-essential
- gcc
- xz-utils
- git
- curl
- vim
- tmux
- ntp
- jq
- llvm
- ufw
state: present
when: node_action == "install"
- name: Stop Aleo services before update
ansible.builtin.systemd:
name: "{{ item }}"
state: stopped
loop:
- aleo-client
- aleo-prover
when: node_action == "update"
- name: Download Rustup installer
ansible.builtin.get_url:
url: https://sh.rustup.rs
dest: "/tmp/rustup.sh"
mode: '0755'
when: node_action == "install"
- name: Install Rustup and Rust
ansible.builtin.shell: sh /tmp/rustup.sh -y
args:
creates: "{{ ansible_env.HOME }}/.cargo/bin/rustup"
when: node_action == "install" or node_action == "update"
- name: Update Rust to the latest stable version
ansible.builtin.shell: "{{ ansible_env.HOME }}/.cargo/bin/rustup update stable"
environment:
PATH: "{{ ansible_env.PATH }}:{{ ansible_env.HOME }}/.cargo/bin"
when: node_action == "install" or node_action == "update"
- name: Clone snarkOS from GitHub repository (fork with fixes)
ansible.builtin.git:
repo : 'https://github.com/AleoHQ/snarkOS.git'
#repo: 'https://github.com/BeckerFelix/snarkOS.git'
dest: "{{ ansible_env.HOME }}/snarkOS"
version: mainnet
#version: fix/hotfix-mismatched-types # Specify the fork's branch
depth: 1
force: yes
when: node_action == "install" or node_action == "update"
- name: Install snarkOS
when: node_action == "install" or node_action == "update"
block:
- name: Run build_ubuntu.sh
ansible.builtin.command: bash build_ubuntu.sh
args:
chdir: "{{ ansible_env.HOME }}/snarkOS"
- name: Install snarkOS using cargo with specific Rust version
ansible.builtin.shell: "{{ ansible_env.HOME }}/.cargo/bin/rustup run stable cargo install --path ."
args:
chdir: "{{ ansible_env.HOME }}/snarkOS"
environment:
PATH: "{{ ansible_env.HOME }}/.cargo/bin:{{ ansible_env.PATH }}"
- name: Generate an Aleo account and store keys
when: node_action == "install"
block:
- name: Generate Aleo account
ansible.builtin.command: snarkos account new
args:
chdir: "{{ ansible_env.HOME }}/snarkOS"
environment:
PATH: "{{ ansible_env.HOME }}/.cargo/bin:{{ ansible_env.PATH }}"
register: account_output
- name: Save keys to a file
ansible.builtin.copy:
content: "{{ account_output.stdout }}"
dest: "{{ ansible_env.HOME }}/aleo/account_new.txt"
mode: "750"
- name: Extract Prover Private Key
shell: grep "Private Key" /root/aleo/account_new.txt | awk '{print $3}'
register: prover_private_key_output
when: node_action == "install"
- name: Set Fact for Prover Private Key
set_fact:
prover_private_key: "{{ prover_private_key_output.stdout }}"
when: node_action == "install"
- name: Create Aleo client service
ansible.builtin.template:
src: aleo-client.service.j2
dest: /etc/systemd/system/aleo-client.service
mode: "0770"
when: node_action == "install"
- name: Create Aleo prover service
ansible.builtin.template:
src: aleo-prover.service.j2
dest: /etc/systemd/system/aleo-prover.service
when: node_action == "install"
- name: Enable and start services
ansible.builtin.systemd:
name: "{{ item }}"
state: started
enabled: true
loop:
- aleo-client
- aleo-prover
when: node_action == "install"
- name: Remove Aleo
when: node_action == "remove"
block:
- name: Stop and disable Aleo services
ansible.builtin.systemd:
name: "{{ item }}"
state: stopped
enabled: false
loop:
- aleo-client
- aleo-prover
ignore_errors: true
- name: Remove Aleo files and configurations
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- "{{ ansible_env.HOME }}/snarkOS"
- "/etc/systemd/system/aleo-client.service"
- "/etc/systemd/system/aleo-prover.service"
- name: Print keys
ansible.builtin.debug:
msg: "Aleo account keys are stored in {{ ansible_env.HOME }}/aleo/account_new.txt"
- name: Reload systemd manager configuration
ansible.builtin.systemd:
daemon_reload: true
when: node_action == "install" or node_action == "update"
- name: Restart Aleo services
ansible.builtin.systemd:
name: "{{ item }}"
state: restarted
enabled: true
loop:
- aleo-client
- aleo-prover
when: node_action == "install" or node_action == "update"