Mercurial > code > home > repos > infra
annotate tasks.py @ 234:3f7ebff619e3
much faster `inv all` since pyinfra bug was fixed
author | drewp@bigasterisk.com |
---|---|
date | Sun, 29 Oct 2023 21:27:10 -0700 |
parents | 117cd86ffb53 |
children | 3af02e24eaf9 |
rev | line source |
---|---|
0
1550a6db59b3
first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff
changeset
|
1 from invoke import task |
1550a6db59b3
first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff
changeset
|
2 |
1 | 3 cmd = ''' |
0
1550a6db59b3
first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff
changeset
|
4 HOME=/root |
1550a6db59b3
first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff
changeset
|
5 export HOME |
1550a6db59b3
first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff
changeset
|
6 eval `keychain --quiet --eval id_ecdsa` |
1550a6db59b3
first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff
changeset
|
7 cd /my/proj/infra |
202 | 8 pdm run pyinfra ''' |
1 | 9 |
205 | 10 |
139 | 11 def _run(ctx, s): |
12 ctx.run(cmd + 'inventory.py %s' % s, pty=True, echo=True) | |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
23
diff
changeset
|
13 |
103
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
96
diff
changeset
|
14 |
59
fa7a71b8a97f
more dns checks, including from inside containers in k8s`
drewp@bigasterisk.com
parents:
54
diff
changeset
|
15 @task |
205 | 16 def users(ctx): |
17 _run(ctx, 'users.py') | |
18 | |
59
fa7a71b8a97f
more dns checks, including from inside containers in k8s`
drewp@bigasterisk.com
parents:
54
diff
changeset
|
19 |
139 | 20 @task |
205 | 21 def ssh(ctx): |
22 _run(ctx, 'ssh.py') | |
23 | |
139 | 24 |
25 @task | |
205 | 26 def system(ctx): |
27 _run(ctx, 'system.py') | |
28 | |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
23
diff
changeset
|
29 |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
23
diff
changeset
|
30 @task |
205 | 31 def apt(ctx): |
32 _run(ctx, 'apt.py') | |
33 | |
155 | 34 |
35 @task | |
205 | 36 def packages(ctx): |
37 _run(ctx, 'packages.py') | |
38 | |
5 | 39 |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
1
diff
changeset
|
40 @task |
205 | 41 def net(ctx): |
42 _run(ctx, 'net.py') | |
43 | |
12 | 44 |
139 | 45 @task |
205 | 46 def dns(ctx): |
47 _run(ctx, 'dns.py') | |
48 | |
139 | 49 |
50 @task | |
205 | 51 def dns_check(ctx): |
52 _run(ctx, 'dns_check.py -v') | |
53 | |
103
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
96
diff
changeset
|
54 |
68 | 55 @task |
205 | 56 def dns_k8s_check(ctx): |
57 ctx.run('env/bin/python dns_k8s_check.py', pty=True) | |
58 | |
8 | 59 |
14 | 60 @task |
205 | 61 def wireguard(ctx): |
62 _run(ctx, 'wireguard.py') | |
63 | |
14 | 64 |
139 | 65 @task |
205 | 66 def kube(ctx): |
67 _run(ctx, 'kube.py') | |
68 | |
8 | 69 |
70 @task | |
205 | 71 def kube_bang(ctx): |
72 _run(ctx, 'kube.py --limit bang') | |
73 | |
16 | 74 |
139 | 75 @task |
205 | 76 def sync(ctx): |
77 _run(ctx, 'sync.py') | |
78 | |
103
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
96
diff
changeset
|
79 |
96
b70070570e10
new task for building ntop from source
drewp@bigasterisk.com
parents:
72
diff
changeset
|
80 @task |
205 | 81 def mail(ctx): |
82 _run(ctx, 'mail.py') | |
83 | |
110 | 84 |
85 @task | |
205 | 86 def home(ctx): |
87 _run(ctx, 'home.py') | |
88 | |
139 | 89 |
90 @task | |
205 | 91 def pipe(ctx): |
92 ctx.run(cmd + 'inventory.py pipe.py --limit pipe', pty=True) | |
93 | |
96
b70070570e10
new task for building ntop from source
drewp@bigasterisk.com
parents:
72
diff
changeset
|
94 |
111 | 95 @task |
205 | 96 def multikube(ctx): # danger- wipes previous k3s |
111 | 97 from multikube_config import server_node, nodes |
98 ctx.run(cmd + 'inventory.py multikube_wipe.py', pty=True) | |
99 ctx.run(cmd + f'inventory.py multikube.py --limit {server_node}', pty=True) | |
113
c520672d0930
closer to multi-node k3s working, but still doesn't quite network right
drewp@bigasterisk.com
parents:
111
diff
changeset
|
100 if nodes: |
136
375515ab60ba
multikube experiment junk. do not run
drewp@bigasterisk.com
parents:
126
diff
changeset
|
101 ctx.run(cmd + f'inventory.py multikube.py {" ".join(f"--limit {n}" for n in nodes)}', pty=True) |
375515ab60ba
multikube experiment junk. do not run
drewp@bigasterisk.com
parents:
126
diff
changeset
|
102 print("""now try |
375515ab60ba
multikube experiment junk. do not run
drewp@bigasterisk.com
parents:
126
diff
changeset
|
103 curl http://10.43.0.10:9153/metrics | head |
375515ab60ba
multikube experiment junk. do not run
drewp@bigasterisk.com
parents:
126
diff
changeset
|
104 k3s kubectl run hello --image crccheck/hello-world |
375515ab60ba
multikube experiment junk. do not run
drewp@bigasterisk.com
parents:
126
diff
changeset
|
105 curl -m2 http://`kubectl get pod/hello '-o=jsonpath={.status.podIP}'`:8000 |
375515ab60ba
multikube experiment junk. do not run
drewp@bigasterisk.com
parents:
126
diff
changeset
|
106 """) |
111 | 107 |
16 | 108 |
60 | 109 @task |
54 | 110 def all(ctx): |
60 | 111 configs = [ |
112 'users.py', | |
113 'ssh.py', | |
114 'system.py', | |
155 | 115 'apt.py', |
60 | 116 'packages.py', |
117 'net.py', | |
118 'dns.py', | |
119 'wireguard.py', | |
120 'kube.py', | |
121 'sync.py', | |
122 'mail.py', | |
110 | 123 'home.py', |
60 | 124 ] |
234
3f7ebff619e3
much faster `inv all` since pyinfra bug was fixed
drewp@bigasterisk.com
parents:
226
diff
changeset
|
125 ctx.run(' '.join([cmd, 'inventory.py'] + configs), pty=True) |
54 | 126 ctx.run('touch /my/proj/infra/ran_all.timestamp') |
127 | |
128 | |
16 | 129 @task |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
1
diff
changeset
|
130 def get_fact(ctx, host='dash', fact='server.LinuxDistribution'): |
8 | 131 ctx.run(cmd + f'{host} -vv fact {fact}', pty=True) |