annotate net/net.py @ 329:2bbcf00b8d2a

hgignore and reformat
author drewp@bigasterisk.com
date Sun, 23 Feb 2025 15:08:58 -0800
parents 5b88b38f2471
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
1 from pyinfra.context import host
227
eef9d075b3ca reformat
drewp@bigasterisk.com
parents: 223
diff changeset
2 from pyinfra.operations import apt, files, server, systemd
35
51c2f861764f refactor
drewp@bigasterisk.com
parents: 34
diff changeset
3
283
drewp@bigasterisk.com
parents: 278
diff changeset
4
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
5 def no_ufw():
289
65e28d2e0cd8 move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents: 288
diff changeset
6 # On pipe:
37
fbd0849dfdbd redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents: 36
diff changeset
7 # 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
8 # test connections from the outside:
fbd0849dfdbd redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents: 36
diff changeset
9 # http://www.t1shopper.com/tools/port-scanner/
fbd0849dfdbd redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents: 36
diff changeset
10 # On prime:
fbd0849dfdbd redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents: 36
diff changeset
11 # using digitalocean network config:
fbd0849dfdbd redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents: 36
diff changeset
12 # 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
13 apt.packages(packages=['ufw'], present=False)
35
51c2f861764f refactor
drewp@bigasterisk.com
parents: 34
diff changeset
14
103
8b8ef9d8f0fd dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents: 100
diff changeset
15
289
65e28d2e0cd8 move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents: 288
diff changeset
16 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
17 # 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
18 # 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
19 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
20 '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
21 '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
22 ])
65e28d2e0cd8 move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents: 288
diff changeset
23 # needs reboot if this changed
107
d70816c7c7db fix pipe net forwarding after update to ubuntu 22.04
drewp
parents: 103
diff changeset
24
188
087b84e68765 comment
drewp@bigasterisk.com
parents: 162
diff changeset
25
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
26 def no_ipv6():
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
27 server.sysctl(key='net.ipv6.conf.all.disable_ipv6', value=1, persist=True)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
28
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
29
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
30 def special_configs():
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
31 if host.name == 'prime':
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
32 files.template(
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
33 src="net/files/prime.network",
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
34 dest="/etc/systemd/network/99-prime.network",
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
35 )
289
65e28d2e0cd8 move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents: 288
diff changeset
36
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
37 elif host.name == 'pipe':
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
38 files.template(src="net/files/pipe_10.2.network", dest="/etc/systemd/network/99-10.2.network")
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
39 files.template(src="net/files/pipe_isp.network", dest="/etc/systemd/network/99-isp.network")
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
40 server.sysctl(key='net.ipv4.ip_forward', value=1, persist=True)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
41 files.template(src="net/files/house_net.service", dest="/etc/systemd/system/house_net.service", out_interface='eth0')
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
42 systemd.service(service='house_net.service', daemon_reload=True, enabled=True, running=True, restarted=True)
35
51c2f861764f refactor
drewp@bigasterisk.com
parents: 34
diff changeset
43
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
44 elif host.name == 'ditto':
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
45 files.template(
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
46 src="net/files/ditto-netplan.yaml",
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
47 dest="/etc/netplan/00-installer-config.yaml",
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
48 create_remote_dir=True,
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
49 )
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
50
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
51 else:
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
52 return
289
65e28d2e0cd8 move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
drewp@bigasterisk.com
parents: 288
diff changeset
53 systemd.service(service='systemd-networkd.service', enabled=True, running=True, restarted=True)
115
8012f6095220 update to current configs
drewp@bigasterisk.com
parents: 107
diff changeset
54
69
659e4b228909 new host 'pipe'
drewp@bigasterisk.com
parents: 67
diff changeset
55
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
56 operations = [
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
57 no_ufw,
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
58 iptables_version,
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
59 no_ipv6,
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
60 special_configs,
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 320
diff changeset
61 ]