Mercurial > code > home > repos > infra
annotate dns.py @ 179:b63ed77141fd
refactor
author | drewp@bigasterisk.com |
---|---|
date | Sat, 25 Mar 2023 18:44:13 -0700 |
parents | e3212146960b |
children | 33db4d39e554 |
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 |
179 | 23 def standard_host_dns(): |
24 files.template(src='templates/hosts.j2', dest='/etc/hosts') | |
25 files.link(path='/etc/resolv.conf', target='/run/systemd/resolve/resolv.conf', force=True) | |
26 files.template(src='templates/resolved.conf.j2', dest='/etc/systemd/resolved.conf') | |
27 systemd.service(service='systemd-resolved.service', running=True, restarted=True) | |
94 | 28 |
179 | 29 standard_host_dns() |
94 | 30 |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
31 if host.name == 'bang': |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
32 systemd.service(service='dnsmasq', enabled=False, running=False) |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
33 files.directory(path='/opt/dnsmasq') |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff
changeset
|
34 |
94 | 35 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
|
36 |
162 | 37 elif host.name == 'ditto': |
38 systemd.service(service='dnsmasq', enabled=False, running=False) | |
39 | |
94 | 40 elif host.name == 'pipe': |
41 systemd.service(service='dnsmasq', enabled=False, running=False) | |
42 files.directory(path='/opt/dnsmasq') | |
116 | 43 dnsmasq_instance('10.2', |
44 house_iface='eth1', | |
134 | 45 dhcp_range='10.2.0.101,10.2.0.240', |
116 | 46 router='10.2.0.3', |
47 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
|
48 out = '/opt/dnsmasq/10.2' |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
49 # 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
|
50 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
|
51 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
|
52 |
51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
drewp@bigasterisk.com
parents:
116
diff
changeset
|
53 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
|
54 systemd.service(service=f'dnsmasq-mtail', enabled=True, restarted=True, daemon_reload=True) |
94 | 55 |
56 else: | |
102 | 57 pass |