Mercurial > code > home > repos > infra
diff dns.py @ 241:075ceead3673
dns work
author | drewp@bigasterisk.com |
---|---|
date | Mon, 11 Dec 2023 21:22:40 -0800 |
parents | 33db4d39e554 |
children | 4e424a144183 |
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(