Mercurial > code > home > repos > infra
diff dns.py @ 94:122ba5444176
dhcp,dns to pipe
author | drewp@bigasterisk.com |
---|---|
date | Fri, 15 Jul 2022 14:32:10 -0700 |
parents | dae714e8f620 |
children | 9ec487a381e2 |
line wrap: on
line diff
--- a/dns.py Fri Jul 15 14:27:34 2022 -0700 +++ b/dns.py Fri Jul 15 14:32:10 2022 -0700 @@ -29,21 +29,36 @@ dhcp_hosts.flush() return dhcp_hosts + def resolv_conf_use_systemd_networkd(): files.link(path='/etc/resolv.conf', target='/run/systemd/resolve/resolv.conf', force=True) + + def resolv_conf_static_file(): files.file(path='/etc/resolv.conf', present=False, force=True) - files.template(src='templates/resolv.conf.j2', - dest='/etc/resolv.conf', - # review this- it's probably a bad dep on bang. maybe both 10.5.0.1 and a public ns would be ok - ns='10.5.0.1' if host.name in ['prime', 'plus'] else '10.2.0.1', - force=True) + files.template( + src='templates/resolv.conf.j2', + dest='/etc/resolv.conf', + # review this- it's probably a bad dep on bang. maybe both 10.5.0.1 and a public ns would be ok + ns='10.5.0.1' if host.name in ['prime', 'plus'] else '10.2.0.3', + force=True) + -def dnsmasq_instance(dhcp_hosts, net_name): +def dnsmasq_instance(net_name, house_iface, dhcp_range, router): files.directory(path=f'/opt/dnsmasq/{net_name}') - files.template(src='templates/dnsmasq/dnsmasq.conf.j2', dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', net=net_name) + files.template( + src='templates/dnsmasq/dnsmasq.conf.j2', + dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', + net=net_name, + house_iface=house_iface, + dhcp_range=dhcp_range, + router=router, + dhcp_enabled=net_name == '10.2' and host.name in [ + #'bang', + 'pipe', + ]) files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name) - files.template(src=dhcp_hosts.name, dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name) + files.template(src='/dev/null', dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name) files.template(src='templates/dnsmasq/dnsmasq.service.j2', dest=f'/etc/systemd/system/dnsmasq_{net_name}.service', @@ -51,28 +66,28 @@ if net_name == '10.2': systemd.service(service=f'dnsmasq_{net_name}', enabled=True, restarted=True, daemon_reload=True) # 10.5 is after wireguard setup - + + +files.template(src='templates/hosts.j2', dest='/etc/hosts') +resolv_conf_use_systemd_networkd() +files.template(src='templates/resolved.conf.j2', dest='/etc/systemd/resolved.conf') +systemd.service(service='systemd-resolved.service', running=True, restarted=True) + if host.name == 'bang': - resolv_conf_static_file() apt.packages(packages=['dnsmasq']) systemd.service(service='dnsmasq', enabled=False, running=False) files.directory(path='/opt/dnsmasq') - dhcp_hosts = prepare_dhcp_hosts() + #dhcp_hosts = prepare_dhcp_hosts() - dnsmasq_instance(dhcp_hosts, '10.2') - dnsmasq_instance(dhcp_hosts, '10.5') # only works after wireguard is up + # dnsmasq_instance('10.2', house_iface='ens5', dhcp_range='unused', router='unused') + dnsmasq_instance('10.5', house_iface='unused', dhcp_range='unused', router='unused') # only works after wireguard is up - -if host.name in [ - 'garage', - 'dash', - 'slash', - 'frontbed', - 'prime', - 'pipe' -]: - resolv_conf_use_systemd_networkd() - files.template(src='templates/hosts.j2', dest='/etc/hosts') - files.template(src='templates/resolved.conf.j2', dest='/etc/systemd/resolved.conf') - systemd.service(service='systemd-resolved.service', running=True, restarted=True) +elif host.name == 'pipe': + apt.packages(packages=['dnsmasq']) + 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.20,10.2.0.120', router='10.2.0.3') + +else: + pass \ No newline at end of file