diff dns.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 828d3f4da54b
line wrap: on
line diff
--- a/dns.py	Sun Apr 21 17:01:13 2024 -0700
+++ b/dns.py	Sun Apr 21 17:07:23 2024 -0700
@@ -5,9 +5,6 @@
 import pyinfra
 from pyinfra import host
 from pyinfra.operations import files, systemd, server
-from pyinfra.facts.server import Arch, LinuxDistribution
-
-is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux']
 
 
 def dnsmasq_instance(net_name,
@@ -41,7 +38,7 @@
 
 def standard_host_dns():
     files.template(src='templates/hosts.j2', dest='/etc/hosts')
-    if is_pi:
+    if 'pi' in host.groups:
         files.put(dest='/etc/resolv.conf',
                   src=StringIO('''
 # written by pyinfra
@@ -91,8 +88,8 @@
                      listen_address='unused')  # only works after wireguard is up
 elif host.name == 'ditto':
     rpi_iscsi_volumes()  # move out of this file- it's not dns
-elif host.name == 'pipe':
 # move out of this file- it's not dns
+if host.name == 'pipe':
     rpi_net_boot()
     files.directory(path='/opt/dnsmasq')
     dnsmasq_instance('10.2',
@@ -102,10 +99,10 @@
                      dhcp_hosts_filename='templates/dnsmasq/dhcp_hosts.j2')
     out = '/opt/dnsmasq/10.2'
     # This mtail is for dhcp command counts and errors. Another monitor in lanscape/ reads the leases file.
-    files.template(src='templates/dnsmasq/metrics.mtail.j2', dest=f'{out}/metrics.mtail')
-    files.template(src='templates/dnsmasq/run_mtail.sh', dest=f'{out}/run_mtail.sh')
+    files.put(src='files/dnsmasq/metrics.mtail', dest=f'{out}/metrics.mtail')
+    files.put(src='files/dnsmasq/run_mtail.sh', dest=f'{out}/run_mtail.sh')
 
-    files.template(src='templates/dnsmasq/dnsmasq-mtail.service.j2', dest='/etc/systemd/system/dnsmasq-mtail.service')
+    files.put(src='files/dnsmasq/dnsmasq-mtail.service', dest='/etc/systemd/system/dnsmasq-mtail.service')
     systemd.service(service='dnsmasq-mtail', enabled=True, restarted=True, daemon_reload=True)
 
     # Serve another dns, no dhcp, and include the dynamic-blocking file written by net_routes.