Mercurial > code > home > repos > infra
comparison system.py @ 155:522f26c8f691
split apt.py from system.py
author | drewp@bigasterisk.com |
---|---|
date | Thu, 16 Mar 2023 17:42:17 -0700 |
parents | 2065998876e4 |
children | 0d37dde619d0 |
comparison
equal
deleted
inserted
replaced
154:89e7dc25dd72 | 155:522f26c8f691 |
---|---|
1 import os | 1 import os |
2 | 2 |
3 from pyinfra import host | 3 from pyinfra import host |
4 from pyinfra.facts.server import LinuxDistribution | 4 from pyinfra.facts.server import LinuxDistribution |
5 from pyinfra.facts.files import FindFiles | |
6 from pyinfra.facts.server import Arch | |
7 from pyinfra.operations import apt, files, server, systemd | 5 from pyinfra.operations import apt, files, server, systemd |
8 | 6 |
9 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] | 7 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] |
10 | 8 |
11 TZ = 'America/Los_Angeles' | 9 TZ = 'America/Los_Angeles' |
13 | 11 |
14 def timezone(): | 12 def timezone(): |
15 files.link(path='/etc/localtime', target=f'/usr/share/zoneinfo/{TZ}') | 13 files.link(path='/etc/localtime', target=f'/usr/share/zoneinfo/{TZ}') |
16 files.replace(path='/etc/timezone', text='.*', replace=TZ) | 14 files.replace(path='/etc/timezone', text='.*', replace=TZ) |
17 | 15 |
18 def pkg_keys(): | |
19 # apt.key(keyserver='keyserver.ubuntu.com', keyid='04EE7237B7D453EC') | |
20 # apt.key(keyserver='keyserver.ubuntu.com', keyid='648ACFD622F3D138') | |
21 # apt.key(keyserver='keyserver.ubuntu.com', keyid='8B48AD6246925553') | |
22 # apt.key(keyserver='keyserver.ubuntu.com', keyid='F24AEA9FB05498B7') | |
23 if host.name != 'prime': | |
24 apt.key(keyserver='keyserver.ubuntu.com', keyid='D0392EC59F9583BA') | |
25 apt.key(src='https://dl.google.com/linux/linux_signing_key.pub') | |
26 apt.key(src='https://ftp-master.debian.org/keys/archive-key-8-security.asc') | |
27 apt.key(src='https://ftp-master.debian.org/keys/archive-key-8.asc') | |
28 apt.key(src='https://ftp-master.debian.org/keys/archive-key-9-security.asc') | |
29 apt.key(src='https://packages.microsoft.com/keys/microsoft.asc') | |
30 apt.key(src='https://deb.nodesource.com/gpgkey/nodesource.gpg.key') | |
31 | |
32 # Failed to fetch https://repo.steampowered.com/steam/dists/stable/InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F24AEA9FB05498B7 | |
33 | |
34 def apt_sources(): | |
35 if host.get_fact(Arch) == 'x86_64': | |
36 server.shell(commands=['dpkg --add-architecture i386']) | |
37 | |
38 files.template(src='templates/sources.list.j2', dest='/etc/apt/sources.list') | |
39 if host.get_fact(FindFiles, '/etc/apt/sources.list.d/', quote_path=True): | |
40 raise SystemExit(f"new files in {host.name} /etc/apt/sources.list.d/ - please remove") | |
41 apt.packages(update=True, | |
42 cache_time=86400, | |
43 packages=['tzdata'], | |
44 force=True, | |
45 _env={ | |
46 'TZ': TZ, | |
47 'LANG': 'en_US.UTF-8', | |
48 'DEBIAN_FRONTEND': 'noninteractive' | |
49 }) | |
50 | 16 |
51 def fstab(): | 17 def fstab(): |
52 fstab_file = f'files/fstab/{host.name}' | 18 fstab_file = f'files/fstab/{host.name}' |
53 if os.path.exists(fstab_file): | 19 if os.path.exists(fstab_file): |
54 files.put(src=fstab_file, dest='/etc/fstab') | 20 files.put(src=fstab_file, dest='/etc/fstab') |
95 dest=f'/etc/systemd/system/zfs_space_metrics.service') | 61 dest=f'/etc/systemd/system/zfs_space_metrics.service') |
96 systemd.service(service=f'zfs_space_metrics', enabled=True, restarted=True, daemon_reload=True) | 62 systemd.service(service=f'zfs_space_metrics', enabled=True, restarted=True, daemon_reload=True) |
97 | 63 |
98 server.hostname(hostname=host.name) | 64 server.hostname(hostname=host.name) |
99 timezone() | 65 timezone() |
100 pkg_keys() | |
101 apt_sources() | |
102 fstab() | 66 fstab() |
103 | 67 |
104 if not is_pi: | 68 if not is_pi: |
105 files.line(path='/etc/update-manager/release-upgrades', line="^Prompt=", replace="Prompt=normal") | 69 files.line(path='/etc/update-manager/release-upgrades', line="^Prompt=", replace="Prompt=normal") |
106 | 70 |