Mercurial > code > home > repos > infra
annotate dns.py @ 119:51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
author | drewp@bigasterisk.com |
---|---|
date | Wed, 07 Dec 2022 23:03:57 -0800 |
parents | 6ec849f1a8c9 |
children | 661af5652dfa |
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 |
106 | 5 def dnsmasq_instance(net_name, house_iface, dhcp_range, router, dhcp_hosts_filename='/dev/null'): |
88
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
6 files.directory(path=f'/opt/dnsmasq/{net_name}') |
103
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
102
diff
changeset
|
7 files.template(src='templates/dnsmasq/dnsmasq.conf.j2', |
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
102
diff
changeset
|
8 dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', |
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
102
diff
changeset
|
9 net=net_name, |
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
102
diff
changeset
|
10 house_iface=house_iface, |
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
102
diff
changeset
|
11 dhcp_range=dhcp_range, |
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
102
diff
changeset
|
12 router=router, |
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
102
diff
changeset
|
13 dhcp_enabled=net_name == '10.2' and host.name == 'pipe') |
88
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
14 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name) |
106 | 15 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
|
16 |
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
17 files.template(src='templates/dnsmasq/dnsmasq.service.j2', |
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
18 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service', |
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
19 net=net_name) |
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
20 if net_name == '10.2': |
dae714e8f620
reactor and temporarily cut dep on lanscape
drewp@bigasterisk.com
parents:
81
diff
changeset
|
21 systemd.service(service=f'dnsmasq_{net_name}', enabled=True, restarted=True, daemon_reload=True) |
94 | 22 |
23 | |
24 files.template(src='templates/hosts.j2', dest='/etc/hosts') | |
103
8b8ef9d8f0fd
dead code and templates, reformat, maybe a little refactor
drewp@bigasterisk.com
parents:
102
diff
changeset
|
25 files.link(path='/etc/resolv.conf', target='/run/systemd/resolve/resolv.conf', force=True) |
94 | 26 files.template(src='templates/resolved.conf.j2', dest='/etc/systemd/resolved.conf') |
27 systemd.service(service='systemd-resolved.service', running=True, restarted=True) | |
28 | |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
29 if host.name == 'bang': |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
30 apt.packages(packages=['dnsmasq']) |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
31 systemd.service(service='dnsmasq', enabled=False, running=False) |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
32 files.directory(path='/opt/dnsmasq') |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
33 |
94 | 34 dnsmasq_instance('10.5', house_iface='unused', dhcp_range='unused', router='unused') # only works after wireguard is up |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
35 |
94 | 36 elif host.name == 'pipe': |
37 apt.packages(packages=['dnsmasq']) | |
38 systemd.service(service='dnsmasq', enabled=False, running=False) | |
39 files.directory(path='/opt/dnsmasq') | |
116 | 40 dnsmasq_instance('10.2', |
41 house_iface='eth1', | |
42 dhcp_range='10.2.0.121,10.2.0.200', | |
43 router='10.2.0.3', | |
44 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
|
45 out = '/opt/dnsmasq/10.2' |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
46 # 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
|
47 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
|
48 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
|
49 |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
50 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
|
51 systemd.service(service=f'dnsmasq-mtail', enabled=True, restarted=True, daemon_reload=True) |
94 | 52 |
53 else: | |
102 | 54 pass |