comparison dns.py @ 88:dae714e8f620

reactor and temporarily cut dep on lanscape
author drewp@bigasterisk.com
date Sun, 10 Jul 2022 19:50:52 -0700
parents bf1573dd1947
children 122ba5444176
comparison
equal deleted inserted replaced
87:0409b3b0493f 88:dae714e8f620
5 from pyinfra import host 5 from pyinfra import host
6 from pyinfra.operations import apt, files, server, systemd 6 from pyinfra.operations import apt, files, server, systemd
7 7
8 8
9 def prepare_dhcp_hosts(): 9 def prepare_dhcp_hosts():
10 empty = tempfile.NamedTemporaryFile(mode='wt')
11 return empty
10 lanscape_ip = subprocess.check_output([ 12 lanscape_ip = subprocess.check_output([
11 'kubectl', 13 'kubectl',
12 'get', 14 'get',
13 'svc', 15 'svc',
14 'lanscape', 16 'lanscape',
35 dest='/etc/resolv.conf', 37 dest='/etc/resolv.conf',
36 # review this- it's probably a bad dep on bang. maybe both 10.5.0.1 and a public ns would be ok 38 # review this- it's probably a bad dep on bang. maybe both 10.5.0.1 and a public ns would be ok
37 ns='10.5.0.1' if host.name in ['prime', 'plus'] else '10.2.0.1', 39 ns='10.5.0.1' if host.name in ['prime', 'plus'] else '10.2.0.1',
38 force=True) 40 force=True)
39 41
42 def dnsmasq_instance(dhcp_hosts, net_name):
43 files.directory(path=f'/opt/dnsmasq/{net_name}')
44 files.template(src='templates/dnsmasq/dnsmasq.conf.j2', dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', net=net_name)
45 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name)
46 files.template(src=dhcp_hosts.name, dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name)
47
48 files.template(src='templates/dnsmasq/dnsmasq.service.j2',
49 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service',
50 net=net_name)
51 if net_name == '10.2':
52 systemd.service(service=f'dnsmasq_{net_name}', enabled=True, restarted=True, daemon_reload=True)
53 # 10.5 is after wireguard setup
54
40 if host.name == 'bang': 55 if host.name == 'bang':
41 resolv_conf_static_file() 56 resolv_conf_static_file()
42 apt.packages(packages=['dnsmasq']) 57 apt.packages(packages=['dnsmasq'])
43 systemd.service(service='dnsmasq', enabled=False, running=False) 58 systemd.service(service='dnsmasq', enabled=False, running=False)
44 files.directory(path='/opt/dnsmasq') 59 files.directory(path='/opt/dnsmasq')
45 60
46 dhcp_hosts = prepare_dhcp_hosts() 61 dhcp_hosts = prepare_dhcp_hosts()
47 62
48 for net_name in ['10.2', '10.5']: 63 dnsmasq_instance(dhcp_hosts, '10.2')
49 files.directory(path=f'/opt/dnsmasq/{net_name}') 64 dnsmasq_instance(dhcp_hosts, '10.5') # only works after wireguard is up
50 files.template(src='templates/dnsmasq/dnsmasq.conf.j2', dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', net=net_name)
51 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name)
52 files.template(src=dhcp_hosts.name, dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name)
53 65
54 files.template(src='templates/dnsmasq/dnsmasq.service.j2', 66
55 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service',
56 net=net_name)
57 systemd.service(service=f'dnsmasq_{net_name}', enabled=True, restarted=True, daemon_reload=True)
58
59 if host.name in [ 67 if host.name in [
60 'garage', 68 'garage',
61 'dash', 69 'dash',
62 'slash', 70 'slash',
63 'frontbed', 71 'frontbed',