diff packages.py @ 289:65e28d2e0cd8

move static templates to files/ ; use inventory tags for selecting hosts+features ; other refactors
author drewp@bigasterisk.com
date Sun, 21 Apr 2024 17:07:23 -0700
parents 3af02e24eaf9
children 9a8861a50512
line wrap: on
line diff
--- a/packages.py	Sun Apr 21 17:01:13 2024 -0700
+++ b/packages.py	Sun Apr 21 17:07:23 2024 -0700
@@ -1,12 +1,10 @@
 from io import StringIO
+
 from pyinfra import host
-from pyinfra.facts.server import LinuxDistribution
 from pyinfra.operations import apt, files, server, systemd
 
 import package_lists
 
-is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux']
-
 
 def kitty():
     vers = '0.31.0'  # see https://github.com/kovidgoyal/kitty/releases
@@ -52,12 +50,12 @@
 
 def proper_locate():
     apt.packages(packages='mlocate', present=False)
-    if not is_pi and host.name not in ['prime', 'pipe']:
+    if 'pi' not in host.groups and host.name not in ['prime', 'pipe']:
         apt.packages(packages='plocate')
 
 
 def proper_man():
-    if host.name in ['pipe', 'prime'] or is_pi:
+    if 'small' in host.groups or 'pi' in host.groups:
         apt.packages(packages=['mandb'], present=False)
 
 
@@ -65,14 +63,12 @@
     systemd.service(service='nginx', enabled=False, running=False)
 
 
-kw = dict(present=True, latest=True)
-
-apt.packages(packages=package_lists.setup, **kw)
+apt.packages(packages=package_lists.setup, latest=True)
 
 
 def roblox():
-    server.shell('flatpak install -y org.freedesktop.Platform/x86_64/23.08')
-    server.shell('flatpak install -y flathub org.vinegarhq.Vinegar')  # (roblox runner)
+    server.shell(commands='flatpak install -y org.freedesktop.Platform/x86_64/23.08')
+    server.shell(commands='flatpak install -y flathub org.vinegarhq.Vinegar')  # (roblox runner)
     files.put(
         src=StringIO(
             #"#!/bin/sh\nexec flatpak run org.vinegarhq.Vinegar player run 'roblox-player:1'\n"
@@ -97,35 +93,28 @@
     ])
 
 
-if not is_pi:
-    if host.name != 'pipe':
-        apt.packages(packages=['reptyr'])
-    kitty()
-else:
-    apt.packages(packages=package_lists.pi_setup)
-
 proper_locate()
 proper_man()
 
-apt.packages(packages=package_lists.general, **kw)
-apt.packages(packages=package_lists.debug, **kw)
-
-if host.name in ["bang", 'ditto']:
-    apt.packages(packages=package_lists.for_bang_ditto, **kw)
+apt.packages(packages=package_lists.general, latest=True)
+apt.packages(packages=package_lists.debug, latest=True)
 
 if host.name == "pipe":
-    apt.packages(packages=package_lists.for_pipe, **kw)
+    apt.packages(packages=package_lists.for_pipe, latest=True)
+
+if host.name != 'pipe':
+    apt.packages(packages=['reptyr'])
 
 if host.name == "prime":
-    apt.packages(packages=package_lists.for_prime, **kw)
+    apt.packages(packages=package_lists.for_prime, latest=True)
 
 if host.name == 'plus':
-    apt.packages(packages=package_lists.laptop, **kw)
+    apt.packages(packages=package_lists.laptop, latest=True)
 
-if host.name in ['dash', 'slash', 'ditto', 'dot']:
-    apt.packages(packages=package_lists.k8s_node_with_nvidia_gpu(host.name))  # no kw, or apt will remove nvidia-utils-VERS (!)
+if host.data.get('gpu'):
+    apt.packages(packages=package_lists.k8s_node_with_nvidia_gpu(host.name))
 
-if host.name in ['dash', 'slash', 'ditto']:
+if host.data.get('k8s_admin'):
     podman()
 
 is_kube_node = host.name in ['dash', 'slash', 'ditto', 'ws-printer', 'li-drums']
@@ -133,19 +122,20 @@
     kube_node()
 
 if host.name == 'ditto':
+    apt.packages(packages=package_lists.for_ditto, latest=True)
     # should have happened in the previous step, but it gets reverted.
     apt.packages(packages=['nvidia-utils-535-server'])
 
-if not is_pi:
-    apt.packages(packages=package_lists.non_pi, **kw)
-else:
-    # move to another file?
-    files.template(src="templates/pigpiod.service.j2", dest="/etc/systemd/system/pigpiod.service")
-    systemd.service(service='pigpiod', daemon_reload=True, enabled=True)
+if 'pi' not in host.groups:
+    kitty()
+    apt.packages(packages=package_lists.non_pi, latest=True)
+
+if 'pi' in host.groups:
+    apt.packages(packages=package_lists.pi_setup)
 
 desktop_env = host.name in ['dash', 'slash', 'plus', 'dot', 'squib', 'pillow']
 if desktop_env:
-    apt.packages(packages=package_lists.xorg + package_lists.desktop, **kw)
+    apt.packages(packages=package_lists.xorg + package_lists.desktop, latest=True)
     roblox()
 if desktop_env or host.name in ['bang', 'ditto']:
     pdm()