diff system.py @ 126:fe3ae7c95e65

collect all apt/sources.list into a central template
author drewp@bigasterisk.com
date Wed, 21 Dec 2022 12:36:06 -0800
parents 69058ad170be
children 168bc1c44e6f
line wrap: on
line diff
--- a/system.py	Wed Dec 07 23:16:27 2022 -0800
+++ b/system.py	Wed Dec 21 12:36:06 2022 -0800
@@ -2,6 +2,7 @@
 
 from pyinfra import host
 from pyinfra.facts.server import LinuxDistribution
+from pyinfra.facts.files import FindFiles
 from pyinfra.operations import apt, files, server, systemd
 
 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux']
@@ -13,6 +14,13 @@
 def timezone():
     files.link(path='/etc/localtime', target=f'/usr/share/zoneinfo/{TZ}')
     files.replace(path='/etc/timezone', text='.*', replace=TZ)
+    
+def apt_sources():
+    server.shell(commands=['dpkg --add-architecture i386'])
+
+    files.template(src='templates/sources.list.j2', dest='/etc/apt/sources.list.j2')
+    if host.get_fact(FindFiles, '/etc/apt/sources.list.d/', quote_path=True):
+        raise SystemExit(f"new files in {host.name} /etc/apt/sources.list.d/ - please remove")
     apt.packages(update=True,
                 cache_time=86400,
                 packages=['tzdata'],
@@ -71,6 +79,7 @@
     systemd.service(service=f'zfs_space_metrics', enabled=True, restarted=True, daemon_reload=True)
 
 timezone()
+apt_sources()
 fstab()
 
 if not is_pi:
@@ -90,4 +99,4 @@
     zfs_metrics()
 
 if host.name == 'prime':
-    smaller_journals()
\ No newline at end of file
+    smaller_journals()