Mercurial > code > home > repos > infra
annotate dns.py @ 213:33db4d39e554
filtered dns adjustments
author | drewp@bigasterisk.com |
---|---|
date | Sat, 12 Aug 2023 14:27:14 -0700 |
parents | b63ed77141fd |
children | 075ceead3673 |
rev | line source |
---|---|
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
1 from pyinfra import host |
102 | 2 from pyinfra.operations import apt, files, systemd |
38 | 3 |
94 | 4 |
213 | 5 def dnsmasq_instance(net_name, |
6 house_iface, | |
7 dhcp_range='10.2.0.10,10.2.0.11', | |
8 listen_address='reqd', | |
9 dhcp_hosts_filename='/dev/null'): | |
88
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
10 files.directory(path=f'/opt/dnsmasq/{net_name}') |
213 | 11 files.template( |
12 src='templates/dnsmasq/dnsmasq.conf.j2', | |
13 dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', | |
14 net=net_name, | |
15 house_iface=house_iface, | |
16 dhcp_range=dhcp_range, | |
17 listen_address=listen_address, | |
18 dhcp_enabled=net_name == '10.2' and host.name == 'pipe', | |
19 dns_server=listen_address, | |
20 router=listen_address, | |
21 ) | |
88
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
22 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name) |
106 | 23 files.template(src=dhcp_hosts_filename, dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name) |
88
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
24 |
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
25 files.template(src='templates/dnsmasq/dnsmasq.service.j2', |
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
26 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service', |
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
27 net=net_name) |
213 | 28 if net_name in ['10.2', '10.2-filtered']: |
88
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
29 systemd.service(service=f'dnsmasq_{net_name}', enabled=True, restarted=True, daemon_reload=True) |
94 | 30 |
213 | 31 |
179 | 32 def standard_host_dns(): |
33 files.template(src='templates/hosts.j2', dest='/etc/hosts') | |
34 files.link(path='/etc/resolv.conf', target='/run/systemd/resolve/resolv.conf', force=True) | |
35 files.template(src='templates/resolved.conf.j2', dest='/etc/systemd/resolved.conf') | |
36 systemd.service(service='systemd-resolved.service', running=True, restarted=True) | |
94 | 37 |
213 | 38 |
179 | 39 standard_host_dns() |
94 | 40 |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
41 if host.name == 'bang': |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
42 systemd.service(service='dnsmasq', enabled=False, running=False) |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
43 files.directory(path='/opt/dnsmasq') |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
44 |
213 | 45 dnsmasq_instance('10.5', house_iface='unused', dhcp_range='unused', |
46 listen_address='unused') # only works after wireguard is up | |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
47 |
162 | 48 elif host.name == 'ditto': |
49 systemd.service(service='dnsmasq', enabled=False, running=False) | |
50 | |
94 | 51 elif host.name == 'pipe': |
52 systemd.service(service='dnsmasq', enabled=False, running=False) | |
53 files.directory(path='/opt/dnsmasq') | |
116 | 54 dnsmasq_instance('10.2', |
55 house_iface='eth1', | |
134 | 56 dhcp_range='10.2.0.101,10.2.0.240', |
213 | 57 listen_address='10.2.0.3', |
116 | 58 dhcp_hosts_filename='templates/dnsmasq/dhcp_hosts.j2') |
119
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
59 out = '/opt/dnsmasq/10.2' |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
60 # This mtail is for dhcp command counts and errors. Another monitor in lanscape/ reads the leases file. |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
61 files.template(src='templates/dnsmasq/metrics.mtail.j2', dest=f'{out}/metrics.mtail') |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
62 files.template(src='templates/dnsmasq/run_mtail.sh', dest=f'{out}/run_mtail.sh') |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
63 |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
64 files.template(src='templates/dnsmasq/dnsmasq-mtail.service.j2', dest=f'/etc/systemd/system/dnsmasq-mtail.service') |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
65 systemd.service(service=f'dnsmasq-mtail', enabled=True, restarted=True, daemon_reload=True) |
94 | 66 |
213 | 67 # Serve another dns, no dhcp, and include the dynamic-blocking file written by net_routes. |
68 dnsmasq_instance( | |
69 net_name='10.2-filtered', | |
70 house_iface='eth1', | |
71 listen_address='10.2.0.4', | |
72 ) |