-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (24 loc) · 872 Bytes
/
main.py
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
import requests
from pyinfra.operations import apt, python, server
# Assumes the repo is configured/apt is updated
apt.packages(
name='Install ZeroTier',
packages=['zerotier-one'],
)
def authorize_server(state, host):
# Run a command on the server and collect status, stderr and stdout
status, stdout, stderr = host.run_shell_command('cat /var/lib/zerotier-one/identity.public')
assert status is True # ensure the command executed OK
# First line of output is the identity
server_id = stdout[0]
# Authorize via the ZeroTier API
response = requests.post('https://my.zerotier.com/.../{0}'.format(server_id))
response.raise_for_status()
python.call(
name='Authorize the server on ZeroTier',
function=authorize_server,
)
server.shell(
name='Execute some shell',
commands=['echo "back to other operations!"'],
)