Mercurial > code > home > repos > infra
view system.py @ 278:4e424a144183
for netboot pi
author | drewp@bigasterisk.com |
---|---|
date | Sat, 30 Mar 2024 00:15:46 -0700 |
parents | ff36727f3a10 |
children | a46eb2a77df7 |
line wrap: on
line source
import os from pyinfra import host from pyinfra.facts.server import LinuxDistribution from pyinfra.operations import apt, files, server, systemd is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] TZ = 'America/Los_Angeles' def timezone(): files.link(path='/etc/localtime', target=f'/usr/share/zoneinfo/{TZ}') files.replace(path='/etc/timezone', text='.*', replace=TZ) def fstab(): fstab_file = f'files/fstab/{host.name}' if os.path.exists(fstab_file): files.put(src=fstab_file, dest='/etc/fstab') def pi_tmpfs(): for line in [ 'tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0', 'tmpfs /tmp tmpfs defaults,noatime 0 0', ]: files.line(path="/etc/fstab", line=line, replace=line) # stop SD card corruption (along with some mounts in fstab) apt.packages(packages=['dphys-swapfile'], present=False) def no_sleep(): server.shell(commands=['systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target']) def nfs_server(): apt.packages(packages=['nfs-kernel-server']) files.template(src='templates/bang_exports.j2', dest='/etc/exports') def smaller_journals(): files.line(name='shorter systemctl log window, for disk space', path='/etc/systemd/journald.conf', line='MaxFileSec', replace="MaxFileSec=7day") def web_forward(): for port in [80, 443]: files.template(src="templates/webforward.service.j2", dest=f"/etc/systemd/system/web_forward_{port}.service", pom_serv_host='bang', port=port) systemd.service(service=f'web_forward_{port}', enabled=True, restarted=True) server.hostname(hostname=host.name) timezone() fstab() if not is_pi: files.line(path='/etc/update-manager/release-upgrades', line="^Prompt=", replace="Prompt=normal") if is_pi and host.name != 'pipe': pi_tmpfs() # this now lives on pipe in /opt/dnsmasq/tftp/f63f14b6/config.txt #files.template(src='templates/boot_config.txt.j2', dest='/boot/config.txt') if host.name in ['bang', 'pipe', 'ditto']: no_sleep() if host.name in ['bang', 'ditto']: nfs_server() if host.name == 'prime': smaller_journals() web_forward() # for space, consider: # k3s crictl rmi --prune # snap list --all | while read snapname ver rev trk pub notes; do if [[ $notes = *disabled* ]]; then snap remove "$snapname" --revision="$rev"; fi; done # podman system reset