Mercurial > code > home > repos > infra
annotate system.py @ 133:706d861f6d95
move boot.config setup to system.py
author | drewp@bigasterisk.com |
---|---|
date | Wed, 21 Dec 2022 13:45:10 -0800 |
parents | 168bc1c44e6f |
children | 5558d8481ddf |
rev | line source |
---|---|
1 | 1 import os |
10
1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
drewp@bigasterisk.com
parents:
6
diff
changeset
|
2 |
1 | 3 from pyinfra import host |
4 from pyinfra.facts.server import LinuxDistribution | |
126
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
5 from pyinfra.facts.files import FindFiles |
130
168bc1c44e6f
stop telling arm machines to get i386 pkgs
drewp@bigasterisk.com
parents:
126
diff
changeset
|
6 from pyinfra.facts.server import Arch |
12
15c5ce7c74b5
refactor, cleanup, split large deploys
drewp@bigasterisk.com
parents:
10
diff
changeset
|
7 from pyinfra.operations import apt, files, server, systemd |
1 | 8 |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
9 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] |
1 | 10 |
11 TZ = 'America/Los_Angeles' | |
12 | |
12
15c5ce7c74b5
refactor, cleanup, split large deploys
drewp@bigasterisk.com
parents:
10
diff
changeset
|
13 server.hostname(hostname=host.name) |
15c5ce7c74b5
refactor, cleanup, split large deploys
drewp@bigasterisk.com
parents:
10
diff
changeset
|
14 |
91 | 15 def timezone(): |
16 files.link(path='/etc/localtime', target=f'/usr/share/zoneinfo/{TZ}') | |
17 files.replace(path='/etc/timezone', text='.*', replace=TZ) | |
126
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
18 |
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
19 def apt_sources(): |
130
168bc1c44e6f
stop telling arm machines to get i386 pkgs
drewp@bigasterisk.com
parents:
126
diff
changeset
|
20 if host.get_fact(Arch) == 'x86_64': |
168bc1c44e6f
stop telling arm machines to get i386 pkgs
drewp@bigasterisk.com
parents:
126
diff
changeset
|
21 server.shell(commands=['dpkg --add-architecture i386']) |
126
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
22 |
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
23 files.template(src='templates/sources.list.j2', dest='/etc/apt/sources.list.j2') |
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
24 if host.get_fact(FindFiles, '/etc/apt/sources.list.d/', quote_path=True): |
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
25 raise SystemExit(f"new files in {host.name} /etc/apt/sources.list.d/ - please remove") |
91 | 26 apt.packages(update=True, |
27 cache_time=86400, | |
28 packages=['tzdata'], | |
29 force=True, | |
30 _env={ | |
31 'TZ': TZ, | |
32 'LANG': 'en_US.UTF-8', | |
33 'DEBIAN_FRONTEND': 'noninteractive' | |
34 }) | |
1 | 35 |
91 | 36 def fstab(): |
37 fstab_file = f'files/fstab/{host.name}' | |
38 if os.path.exists(fstab_file): | |
39 files.put(src=fstab_file, dest='/etc/fstab') | |
1 | 40 |
91 | 41 def pi_tmpfs(): |
1 | 42 for line in [ |
43 'tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0', | |
44 'tmpfs /tmp tmpfs defaults,noatime 0 0', | |
45 ]: | |
46 files.line(path="/etc/fstab", line=line, replace=line) | |
47 | |
48 # stop SD card corruption (along with some mounts in fstab) | |
49 apt.packages(packages=['dphys-swapfile'], present=False) | |
50 | |
51 | |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
52 # don't try to get aufs-dkms on rpi-- https://github.com/docker/for-linux/issues/709 |
91 | 53 def podman_inecure_registry(): |
54 files.template(src='templates/kube/podman_registries.conf.j2', dest='/etc/containers/registries.conf.d/bang.conf') | |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
55 |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
56 |
91 | 57 def no_sleep(): |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
58 server.shell(commands=['systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target']) |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
59 |
91 | 60 def nfs_server(): |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
61 apt.packages(packages=['nfs-kernel-server']) |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
62 files.template(src='templates/bang_exports.j2', dest='/etc/exports') |
37
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
63 |
57 | 64 # sudo zfs set sharenfs="rw=10.5.0.0/16" stor6 |
65 | |
91 | 66 def smaller_journals(): |
37
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
67 files.line(name='shorter systemctl log window, for disk space', |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
68 path='/etc/systemd/journald.conf', |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
69 line='MaxFileSec', |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
70 replace="MaxFileSec=7day") |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
71 |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
72 for port in [80, 443]: |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
73 files.template(src="templates/webforward.service.j2", dest=f"/etc/systemd/system/web_forward_{port}.service", port=port) |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
74 systemd.service(service=f'web_forward_{port}', enabled=True, restarted=True) |
91 | 75 |
118
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
76 def zfs_metrics(): |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
77 files.put(src='files/zfs_metrics/zfs_space_metrics.sh', dest='/opt/zfs_metrics/zfs_space_metrics.sh') |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
78 files.put(src='files/zfs_metrics/zfs.mtail', dest='/opt/zfs_metrics/zfs.mtail') |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
79 files.put(src='files/zfs_metrics/zfs_space_metrics.service', |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
80 dest=f'/etc/systemd/system/zfs_space_metrics.service') |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
81 systemd.service(service=f'zfs_space_metrics', enabled=True, restarted=True, daemon_reload=True) |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
82 |
91 | 83 timezone() |
126
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
84 apt_sources() |
91 | 85 fstab() |
86 | |
87 if not is_pi: | |
88 files.line(path='/etc/update-manager/release-upgrades', line="^Prompt=", replace="Prompt=normal") | |
89 | |
90 if is_pi and host.name != 'pipe': | |
91 pi_tmpfs() | |
133 | 92 files.template(src='templates/boot_config.txt.j2', dest='/boot/config.txt') |
91 | 93 |
94 if not is_pi: | |
95 podman_inecure_registry() | |
96 | |
97 if host.name in ['bang', 'pipe']: | |
98 no_sleep() | |
99 | |
100 if host.name == 'bang': | |
101 nfs_server() | |
118
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
102 zfs_metrics() |
91 | 103 |
104 if host.name == 'prime': | |
126
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
105 smaller_journals() |