bundles/powerdns: rework zone file generation

This commit is contained in:
Franzi 2023-01-29 11:01:48 +01:00
parent 264ea3e8a7
commit ef16a2d081
Signed by: kunsi
GPG key ID: 12E3D2136B818350
2 changed files with 18 additions and 21 deletions

View file

@ -5,26 +5,12 @@ from subprocess import check_output
zone_path = join(repo.path, 'data', 'powerdns', 'files', 'bind-zones')
ZONE_HEADER = """
; _ ____ _ _ _____ _ _ _ _ ____
; / \\ / ___| | | |_ _| | | | \\ | |/ ___|
; / _ \\| | | |_| | | | | | | | \\| | | _
; / ___ \\ |___| _ | | | | |_| | |\\ | |_| |
; /_/ \\_\\____|_| |_| |_| \\___/|_| \\_|\\____|
;
; --> Diese Datei wird von BundleWrap verwaltet! <--
$TTL 60
@ IN SOA ns-1.kunbox.net. hostmaster.kunbox.net. (
{serial}
3600
600
86400
300
)
"""
nameservers = set()
for rnode in sorted(repo.nodes_in_group('dns')):
ZONE_HEADER += '@ IN NS {}.\n'.format(rnode.metadata.get('powerdns/my_hostname', rnode.metadata.get('hostname')))
if not rnode.metadata.get('powerdns/is_secondary'):
# hide the primary nameserver from auto-generated nameserver lists
continue
nameservers.add(rnode.metadata.get('powerdns/my_hostname', rnode.metadata.get('hostname')))
directories = {
'/etc/powerdns/pdns.d': {
@ -102,7 +88,8 @@ if node.metadata.get('powerdns/features/bind', False):
files[f'/var/lib/powerdns/zones/{zone}'] = {
'content_type': 'mako',
'context': {
'header': ZONE_HEADER.format(serial=serial),
'NAMESERVERS': '\n'.join(sorted({f'@ IN NS {ns}.' for ns in nameservers})),
'SERIAL': serial,
'metadata_records': node.metadata.get(f'powerdns/bind-zones/{zone}/records', []),
},
'source': f'bind-zones/{zone}',

View file

@ -1,4 +1,14 @@
${header}
$TTL 60
@ IN SOA ns-primary.kunbox.net. hostmaster.kunbox.net. (
${SERIAL}
3600
600
86400
300
)
${NAMESERVERS}
$ORIGIN kunbox.net.