changeset 241:075ceead3673

dns work
author drewp@bigasterisk.com
date Mon, 11 Dec 2023 21:22:40 -0800
parents b58f05be720a
children 9338ea580828
files dns.py templates/dnsmasq/hosts.j2
diffstat 2 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dns.py	Mon Dec 11 21:22:12 2023 -0800
+++ b/dns.py	Mon Dec 11 21:22:40 2023 -0800
@@ -1,5 +1,8 @@
+from io import StringIO
+import subprocess
+from tempfile import NamedTemporaryFile
 from pyinfra import host
-from pyinfra.operations import apt, files, systemd
+from pyinfra.operations import files, systemd
 
 
 def dnsmasq_instance(net_name,
@@ -20,7 +23,9 @@
         router=listen_address,
     )
     files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name)
-    files.template(src=dhcp_hosts_filename, dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name)
+    
+    dhcp_hosts = subprocess.check_output(['python3', '/my/serv/lanscape/src/public/make_dhcp_hosts.py'], encoding='utf8')
+    files.put(src=StringIO(dhcp_hosts), dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts')
 
     files.template(src='templates/dnsmasq/dnsmasq.service.j2',
                    dest=f'/etc/systemd/system/dnsmasq_{net_name}.service',
@@ -38,22 +43,20 @@
 
 standard_host_dns()
 
+# no default instance; i'll add some specific ones below
+systemd.service(service='dnsmasq', enabled=False, running=False)
+
 if host.name == 'bang':
-    systemd.service(service='dnsmasq', enabled=False, running=False)
     files.directory(path='/opt/dnsmasq')
 
     dnsmasq_instance('10.5', house_iface='unused', dhcp_range='unused',
                      listen_address='unused')  # only works after wireguard is up
 
-elif host.name == 'ditto':
-    systemd.service(service='dnsmasq', enabled=False, running=False)
-
 elif host.name == 'pipe':
-    systemd.service(service='dnsmasq', enabled=False, running=False)
     files.directory(path='/opt/dnsmasq')
     dnsmasq_instance('10.2',
                      house_iface='eth1',
-                     dhcp_range='10.2.0.101,10.2.0.240',
+                     dhcp_range='10.2.0.110,10.2.0.199',
                      listen_address='10.2.0.3',
                      dhcp_hosts_filename='templates/dnsmasq/dhcp_hosts.j2')
     out = '/opt/dnsmasq/10.2'
@@ -61,8 +64,8 @@
     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.template(src='templates/dnsmasq/dnsmasq-mtail.service.j2', dest=f'/etc/systemd/system/dnsmasq-mtail.service')
-    systemd.service(service=f'dnsmasq-mtail', enabled=True, restarted=True, daemon_reload=True)
+    files.template(src='templates/dnsmasq/dnsmasq-mtail.service.j2', 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.
     dnsmasq_instance(
--- a/templates/dnsmasq/hosts.j2	Mon Dec 11 21:22:12 2023 -0800
+++ b/templates/dnsmasq/hosts.j2	Mon Dec 11 21:22:40 2023 -0800
@@ -12,6 +12,8 @@
 10.2.0.13 mqtt3 mqtt3.bigasterisk.com 
 10.2.0.14 mqtt4 mqtt4.bigasterisk.com
 
+10.2.0.15 victorialogs.bigasterisk.com
+
 # sync with /my/proj/infra/inventory.py
 # and with templates/wireguard/wg0.conf.j2
 # Hosts with fixed wg0 addresses:
@@ -30,6 +32,7 @@
 # Hosts with fixed addrs who don't introduce via dhcp:
 # 162.243.138.136   prime.bigasterisk.com
 10.2.0.3 pipe pipe.bigasterisk.com
+# from netdevices.n3
 10.2.0.133 ditto ditto.bigasterisk.com
 {% endif %}