Mercurial > code > home > repos > infra
view system.py @ 202:a5399e8b47b6
upgrade some ubuntu
author | drewp@bigasterisk.com |
---|---|
date | Fri, 30 Jun 2023 22:36:53 -0700 |
parents | 2595cf510c5d |
children | 3fd439ae1380 |
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) # don't try to get aufs-dkms on rpi-- https://github.com/docker/for-linux/issues/709 def podman_insecure_registry(): files.template(src='templates/kube/podman_registries.conf.j2', dest='/etc/containers/registries.conf.d/bang.conf') 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") for port in [80, 443]: files.template(src="templates/webforward.service.j2", dest=f"/etc/systemd/system/web_forward_{port}.service", 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() files.template(src='templates/boot_config.txt.j2', dest='/boot/config.txt') if not is_pi: podman_insecure_registry() if host.name in ['bang', 'pipe', 'ditto']: no_sleep() if host.name in ['bang', 'ditto']: nfs_server() if host.name == 'prime': smaller_journals()