annotate dns.py @ 34:d4fb38f13c79

refactor dns and some other non-net setup
author drewp@bigasterisk.com
date Sat, 15 Jan 2022 15:40:22 -0800
parents
children 4026b6b8028f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
1 from pyinfra import host
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
2 from pyinfra.operations import apt, files, server, systemd
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
3
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
4 if host.name == 'bang':
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
5 apt.packages(packages=['dnsmasq'])
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
6 systemd.service(service='dnsmasq', enabled=False, running=False)
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
7 files.directory(path='/opt/dnsmasq')
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
8
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
9 for net_name in ['10.1', '10.2', '10.5']:
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
10 files.directory(path=f'/opt/dnsmasq/{net_name}')
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
11 files.template(src='templates/dnsmasq/dnsmasq.conf.j2', dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', net=net_name)
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
12 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name)
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
13 files.template(src='templates/dnsmasq/dhcp_hosts.j2', dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name)
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
14
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
15 files.template(src='templates/dnsmasq/dnsmasq.service.j2',
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
16 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service',
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
17 net=net_name)
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
18 systemd.service(service=f'dnsmasq_{net_name}', restarted=True, daemon_reload=True)
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
19
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
20 if host.name in [
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
21 'garage',
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
22 'dash',
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
23 'slash',
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
24 'frontbed',
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
25 'prime',
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
26 ]:
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
27 files.template(src='templates/hosts.j2', dest='/etc/hosts')
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
28
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
29 files.link(path='/etc/resolv.conf', target='/run/systemd/resolve/resolv.conf')
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
30 files.template(src='templates/resolved.conf.j2', dest='/etc/systemd/resolved.conf')
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
31
d4fb38f13c79 refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
diff changeset
32 systemd.service(service='systemd-resolved.service', running=True, restarted=True)