Mercurial > code > home > repos > infra
annotate system.py @ 10:1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
author | drewp@bigasterisk.com |
---|---|
date | Thu, 11 Nov 2021 22:22:34 -0800 |
parents | aa633eb49c63 |
children | 15c5ce7c74b5 |
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 | |
10
1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
drewp@bigasterisk.com
parents:
6
diff
changeset
|
5 from pyinfra.operations import apt, files, server, ssh, systemd |
1 | 6 |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
7 bang_is_old = True # remove after upgrade |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
8 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] |
1 | 9 is_wifi_pi = host.name in ['frontdoor', 'living'] |
10 | |
11 TZ = 'America/Los_Angeles' | |
12 | |
13 # | |
14 # system | |
15 # | |
16 | |
17 server.hostname(hostname=host.name) | |
18 files.link(path='/etc/localtime', target=f'/usr/share/zoneinfo/{TZ}') | |
19 files.replace(path='/etc/timezone', match='.*', replace=TZ) | |
20 apt.packages(update=True, | |
21 cache_time=86400, | |
22 packages=['tzdata'], | |
23 force=True, | |
24 env={ | |
25 'TZ': TZ, | |
26 'LANG': 'en_US.UTF-8', | |
27 'DEBIAN_FRONTEND': 'noninteractive' | |
28 }) | |
29 | |
30 # | |
31 # fstab | |
32 # | |
33 | |
34 fstab_file = f'files/{host.name}_fstab' | |
35 if os.path.exists(fstab_file): | |
36 files.put(src=fstab_file, dest='/etc/fstab') | |
37 if is_pi: | |
38 for line in [ | |
39 'tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0', | |
40 'tmpfs /tmp tmpfs defaults,noatime 0 0', | |
41 ]: | |
42 files.line(path="/etc/fstab", line=line, replace=line) | |
43 | |
44 # stop SD card corruption (along with some mounts in fstab) | |
45 apt.packages(packages=['dphys-swapfile'], present=False) | |
46 | |
47 # | |
48 # pkgs | |
49 # | |
50 | |
51 if not is_pi: | |
52 apt.key(keyserver='keyserver.ubuntu.com', keyid='8B48AD6246925553') | |
53 | |
54 if is_pi: | |
6
aa633eb49c63
have pi use bullseye for working netplan.io pkg
drewp@bigasterisk.com
parents:
3
diff
changeset
|
55 apt.packages(packages=['mandb', 'apt-listchanges'], present=False) |
aa633eb49c63
have pi use bullseye for working netplan.io pkg
drewp@bigasterisk.com
parents:
3
diff
changeset
|
56 files.template(src='templates/pi_sources.list.j2', dest='/etc/apt/sources.list', rel='bullseye') |
aa633eb49c63
have pi use bullseye for working netplan.io pkg
drewp@bigasterisk.com
parents:
3
diff
changeset
|
57 # 'apt upgrade'? |
aa633eb49c63
have pi use bullseye for working netplan.io pkg
drewp@bigasterisk.com
parents:
3
diff
changeset
|
58 apt.packages(update=True, packages=['dirmngr', 'gnupg2', 'apt-utils']) |
1 | 59 |
60 apt.key(src='https://ftp-master.debian.org/keys/archive-key-8.asc') | |
61 apt.key(src='https://ftp-master.debian.org/keys/archive-key-8-security.asc') | |
62 apt.key(src='https://ftp-master.debian.org/keys/archive-key-9-security.asc') | |
63 | |
64 files.file(path='/etc/apt/sources.list.d/raspi.list', present=False) | |
65 | |
66 if is_wifi_pi: | |
67 files.put(dest="/etc/network/interfaces.d/wlan0", src="files/pi_wlan0_powersave") | |
68 ssh.command(host.name, "iw wlan0 set power_save off") | |
69 | |
10
1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
drewp@bigasterisk.com
parents:
6
diff
changeset
|
70 files.template(src='templates/boot_config.txt.j2', dest='/boot/config.txt') |
1 | 71 |
10
1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
drewp@bigasterisk.com
parents:
6
diff
changeset
|
72 if not is_pi and host.name != 'prime': |
1 | 73 apt.key(src='https://dl.google.com/linux/linux_signing_key.pub') |
74 apt.repo(src='deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main') | |
75 | |
76 apt.key(src='https://packages.microsoft.com/keys/microsoft.asc') | |
77 apt.repo(src="deb [arch=amd64,arm64,armhf] http://packages.microsoft.com/repos/code stable main") | |
78 | |
79 apt.ppa(src="ppa:savoury1/blender") | |
80 | |
81 apt.key(keyserver='keyserver.ubuntu.com', keyid='F24AEA9FB05498B7') | |
82 apt.repo(src="deb [arch=amd64,i386] https://repo.steampowered.com/steam/ stable steam") | |
83 | |
84 apt.packages(packages=[ | |
85 'build-essential', | |
10
1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
drewp@bigasterisk.com
parents:
6
diff
changeset
|
86 # 'i2c-tools', |
1 | 87 'rsync', |
10
1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
drewp@bigasterisk.com
parents:
6
diff
changeset
|
88 'dstat', |
1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
drewp@bigasterisk.com
parents:
6
diff
changeset
|
89 'ifstat', |
1 | 90 ]) |
91 | |
2 | 92 if not is_pi: |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
93 apt.packages(packages=[ |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
94 'keychain', |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
95 'python3-docker', |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
96 'python3-invoke', |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
97 'python3-pip', |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
98 'python3-virtualenv', |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
99 'sysstat', |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
100 ]) |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
101 |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
102 if not is_pi and not bang_is_old: |
2 | 103 apt.packages(packages='mlocate', present=False) |
104 apt.packages(packages='plocate') | |
105 | |
1 | 106 # |
107 # ssh | |
108 # | |
109 | |
110 systemd.service( | |
111 service='ssh', | |
112 running=True, | |
113 enabled=True, | |
114 ) | |
115 | |
116 files.line(path='/etc/ssh/ssh_config', line="HashKnownHosts", replace="HashKnownHosts no") | |
117 | |
118 if is_pi: | |
119 auth_keys = '/home/pi/.ssh/authorized_keys' | |
120 files.file(path=auth_keys, user='pi', group='pi', mode=600) | |
121 for pubkey in [ | |
122 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNlR7hereUHqw/RHQau0F7+vQZKAxduM+SD4R76FhC+4Zi078Pv04ZLe9qdM/NBlB/grLGhG58vaGmnWPpJ3QJs= drewp@plus', | |
123 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOR+iV8Qm/rAfmq0epXYfnp5ZTfBl8eidFzw1GmyZ3fPUFAshWn839fQ5DPj9xDPtMy9kTtrB5bK1SnynFzDqzQ= drewp@bang', | |
124 ]: | |
125 files.line(path=auth_keys, line=pubkey, replace=pubkey) | |
126 | |
127 # | |
128 # docker (delete this?) | |
129 # | |
130 | |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
131 # don't try to get aufs-dkms on rpi-- https://github.com/docker/for-linux/issues/709 |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
132 if not is_pi: |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
133 apt.packages(packages=['docker.io'], no_recommends=True) |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
134 files.put(src='files/docker_daemon.json', dest='/etc/docker/daemon.json') |
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
135 systemd.service(service='docker', running=True, enabled=True, restarted=True) |
1 | 136 |
137 if not is_pi: | |
138 files.line(path='/etc/update-manager/release-upgrades', line="^Prompt=", replace="Prompt=normal") | |
139 | |
140 files.line(path='/etc/ssh/sshd_config', line="^UseDNS\b", replace="UseDNS no") | |
141 systemd.service(service='sshd', reloaded=True) | |
142 | |
143 # | |
144 # special hosts | |
145 # | |
146 | |
147 if host.name == "bang": | |
148 apt.packages(packages=[ | |
149 'libzfs2linux', | |
150 'zfsutils-linux', | |
151 'zfs-zed', | |
152 'zfs-auto-snapshot', | |
153 ]) |