Mercurial > code > home > repos > infra
annotate net.py @ 289:65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
author | drewp@bigasterisk.com |
---|---|
date | Sun, 21 Apr 2024 17:07:23 -0700 |
parents | 3af02e24eaf9 |
children | 11d3bcedb9f0 |
rev | line source |
---|---|
7
b6fff51f8676
net.py setup. May not be safe on bang yet
drewp@bigasterisk.com
parents:
diff
changeset
|
1 from pyinfra import host |
227 | 2 from pyinfra.operations import apt, files, server, systemd |
35 | 3 |
283 | 4 |
35 | 5 def cleanup(): |
6 # past attempts | |
82
ff60853d7152
fix for bang dhclient'ing its resolv.conf sometimes
drewp@bigasterisk.com
parents:
72
diff
changeset
|
7 files.file(path='/etc/network/interfaces', present=False) |
7
b6fff51f8676
net.py setup. May not be safe on bang yet
drewp@bigasterisk.com
parents:
diff
changeset
|
8 |
22
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
9 for search_dir in [ |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
10 # search path per `man systemd.network`: |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
11 # /lib/systemd/network # These OS files are ok. |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
12 '/usr/local/lib/systemd/network/', # Probably no such dir. |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
13 '/run/systemd/network/', # Previous netplan attempts dumped in here. |
227 | 14 # '/etc/systemd/network/', # I'm going to work in here. |
22
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
15 ]: |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
16 files.sync( |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
17 src="files/empty_dir/", |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
18 dest=search_dir, |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
19 delete=True, |
301dad3cdb7b
WIP updating to use systemd networkd but it's not done or working, here
drewp@bigasterisk.com
parents:
17
diff
changeset
|
20 ) |
7
b6fff51f8676
net.py setup. May not be safe on bang yet
drewp@bigasterisk.com
parents:
diff
changeset
|
21 |
289
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
22 # On pipe: |
37
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
36
diff
changeset
|
23 # Now using a HW router for this firewall. No incoming connections. |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
36
diff
changeset
|
24 # test connections from the outside: |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
36
diff
changeset
|
25 # http://www.t1shopper.com/tools/port-scanner/ |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
36
diff
changeset
|
26 # On prime: |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
36
diff
changeset
|
27 # using digitalocean network config: |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
36
diff
changeset
|
28 # https://cloud.digitalocean.com/networking/firewalls/f68899ae-1aac-4469-b379-59ce2bbc988f/droplets?i=7c5072 |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
36
diff
changeset
|
29 apt.packages(packages=['ufw'], present=False) |
35 | 30 |
103
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
100
diff
changeset
|
31 |
289
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
32 def iptables_version(): |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
33 # https://github.com/k3s-io/k3s/issues/1812 unclear, but more importantly, this has to be set |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
34 # on pipe in a way that works with the commands in house_net.service (and net_routes) |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
35 server.shell(commands=[ |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
36 'update-alternatives --set iptables /usr/sbin/iptables-legacy', |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
37 'update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy', |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
38 ]) |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
39 # needs reboot if this changed |
107 | 40 |
188 | 41 |
289
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
42 iptables_version() |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
43 server.sysctl(key='net.ipv6.conf.all.disable_ipv6', value=1, persist=True) |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
44 |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
45 if host.name == 'prime': |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
46 cleanup() |
35 | 47 |
289
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
48 files.template( |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
49 src="files/net/prime.network", |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
50 dest="/etc/systemd/network/99-prime.network", |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
51 ) |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
52 systemd.service(service='systemd-networkd.service', enabled=True, running=True, restarted=True) |
115 | 53 |
289
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
54 if host.name == 'bang': |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
55 cleanup() |
69 | 56 |
289
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
57 files.template(src="files/net/bang_10.2.network", dest="/etc/systemd/network/20-10.2.network") |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
58 apt.packages(packages=['network-manager'], present=False) |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
59 systemd.service(service='systemd-networkd.service', enabled=True, running=True, restarted=True) |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
60 |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
61 if host.name == 'pipe': |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
62 cleanup() |
69 | 63 |
289
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
64 files.template(src="files/net/pipe_10.2.network", dest="/etc/systemd/network/99-10.2.network") |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
65 files.template(src="files/net/pipe_isp.network", dest="/etc/systemd/network/99-isp.network") |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
66 server.sysctl(key='net.ipv4.ip_forward', value=1, persist=True) |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
67 files.template(src="files/net/house_net.service", dest="/etc/systemd/system/house_net.service", out_interface='eth0') |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
68 systemd.service(service='house_net.service', daemon_reload=True, enabled=True, running=True, restarted=True) |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
69 systemd.service(service='systemd-networkd.service', enabled=True, running=True, restarted=True) |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
22
diff
changeset
|
70 |
289
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
71 if host.name == 'ditto': |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
72 files.template( |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
73 src="files/net/ditto-netplan.yaml", |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
74 dest="/etc/netplan/00-installer-config.yaml", |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
75 create_remote_dir=True, |
65e28d2e0cd8
move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents:
288
diff
changeset
|
76 ) |
283 | 77 |
251 | 78 systemd.service(service='systemd-networkd.service', enabled=True, running=True, restarted=True) |