comparison dns.py @ 103:8b8ef9d8f0fd

dead code and templates, reformat, maybe a little refactor
author drewp@bigasterisk.com
date Fri, 15 Jul 2022 15:24:44 -0700
parents 9ec487a381e2
children 5faa7e3aa38f
comparison
equal deleted inserted replaced
102:9ec487a381e2 103:8b8ef9d8f0fd
1 from pyinfra import host 1 from pyinfra import host
2 from pyinfra.operations import apt, files, systemd 2 from pyinfra.operations import apt, files, systemd
3 3
4 4
5 def resolv_conf_use_systemd_networkd():
6 files.link(path='/etc/resolv.conf', target='/run/systemd/resolve/resolv.conf', force=True)
7
8
9 def resolv_conf_static_file():
10 files.file(path='/etc/resolv.conf', present=False, force=True)
11 files.template(
12 src='templates/resolv.conf.j2',
13 dest='/etc/resolv.conf',
14 # review this- it's probably a bad dep on bang. maybe both 10.5.0.1 and a public ns would be ok
15 ns='10.5.0.1' if host.name in ['prime', 'plus'] else '10.2.0.3',
16 force=True)
17
18
19 def dnsmasq_instance(net_name, house_iface, dhcp_range, router): 5 def dnsmasq_instance(net_name, house_iface, dhcp_range, router):
20 files.directory(path=f'/opt/dnsmasq/{net_name}') 6 files.directory(path=f'/opt/dnsmasq/{net_name}')
21 files.template( 7 files.template(src='templates/dnsmasq/dnsmasq.conf.j2',
22 src='templates/dnsmasq/dnsmasq.conf.j2', 8 dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf',
23 dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', 9 net=net_name,
24 net=net_name, 10 house_iface=house_iface,
25 house_iface=house_iface, 11 dhcp_range=dhcp_range,
26 dhcp_range=dhcp_range, 12 router=router,
27 router=router, 13 dhcp_enabled=net_name == '10.2' and host.name == 'pipe')
28 dhcp_enabled=net_name == '10.2' and host.name == 'pipe')
29 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name) 14 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name)
30 files.template(src='/dev/null', dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name) 15 files.template(src='/dev/null', dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name)
31 16
32 files.template(src='templates/dnsmasq/dnsmasq.service.j2', 17 files.template(src='templates/dnsmasq/dnsmasq.service.j2',
33 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service', 18 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service',
35 if net_name == '10.2': 20 if net_name == '10.2':
36 systemd.service(service=f'dnsmasq_{net_name}', enabled=True, restarted=True, daemon_reload=True) 21 systemd.service(service=f'dnsmasq_{net_name}', enabled=True, restarted=True, daemon_reload=True)
37 22
38 23
39 files.template(src='templates/hosts.j2', dest='/etc/hosts') 24 files.template(src='templates/hosts.j2', dest='/etc/hosts')
40 resolv_conf_use_systemd_networkd() 25 files.link(path='/etc/resolv.conf', target='/run/systemd/resolve/resolv.conf', force=True)
41 files.template(src='templates/resolved.conf.j2', dest='/etc/systemd/resolved.conf') 26 files.template(src='templates/resolved.conf.j2', dest='/etc/systemd/resolved.conf')
42 systemd.service(service='systemd-resolved.service', running=True, restarted=True) 27 systemd.service(service='systemd-resolved.service', running=True, restarted=True)
43 28
44 if host.name == 'bang': 29 if host.name == 'bang':
45 apt.packages(packages=['dnsmasq']) 30 apt.packages(packages=['dnsmasq'])