2020-10-16 15:44:31 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from os import listdir
|
|
|
|
from os.path import isfile, join
|
|
|
|
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
|
|
|
|
3600
|
|
|
|
86400
|
|
|
|
300
|
|
|
|
)
|
|
|
|
"""
|
2020-10-17 10:56:17 +00:00
|
|
|
for rnode in sorted(repo.nodes_in_group('dns')):
|
2020-10-17 11:04:28 +00:00
|
|
|
ZONE_HEADER += '@ IN NS {}.\n'.format(rnode.metadata.get('powerdns', {}).get('my_hostname', rnode.hostname))
|
2020-10-16 15:44:31 +00:00
|
|
|
|
2020-10-16 11:19:44 +00:00
|
|
|
directories = {
|
|
|
|
'/etc/powerdns/pdns.d': {
|
|
|
|
'purge': True,
|
2020-10-16 15:59:46 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:pdns-server',
|
|
|
|
'pkg_apt:pdns-backend-bind',
|
|
|
|
'pkg_apt:pdns-backend-pgsql',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:pdns:restart',
|
|
|
|
},
|
2020-10-16 11:19:44 +00:00
|
|
|
},
|
2020-10-16 15:44:31 +00:00
|
|
|
'/var/lib/powerdns/zones': {
|
|
|
|
'purge': True,
|
2020-10-16 15:59:46 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:pdns-backend-bind',
|
|
|
|
},
|
2020-10-16 15:44:31 +00:00
|
|
|
}
|
2020-10-16 11:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
files = {
|
|
|
|
'/etc/powerdns/pdns.conf': {
|
2020-10-16 15:44:31 +00:00
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'api_key': node.metadata['powerdns']['api_key'],
|
2020-10-17 10:56:17 +00:00
|
|
|
'my_hostname': node.metadata['powerdns'].get('my_hostname', node.name),
|
2020-10-16 21:02:47 +00:00
|
|
|
'is_secondary': node.metadata['powerdns'].get('is_secondary', False),
|
2020-10-17 10:56:17 +00:00
|
|
|
'my_primary_servers': node.metadata['powerdns'].get('my_primary_servers', {}),
|
2020-10-16 15:44:31 +00:00
|
|
|
},
|
2020-10-16 15:59:46 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:pdns-server',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:pdns:restart',
|
|
|
|
},
|
2020-10-16 15:44:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd = {
|
|
|
|
'pdns': {
|
2020-10-16 11:19:44 +00:00
|
|
|
'needs': {
|
2020-10-16 15:44:31 +00:00
|
|
|
'directory:',
|
|
|
|
'file:',
|
2020-10-16 15:59:46 +00:00
|
|
|
'pkg_apt:pdns-server',
|
|
|
|
'pkg_apt:pdns-backend-bind',
|
|
|
|
'pkg_apt:pdns-backend-pgsql',
|
2020-10-16 11:19:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-16 15:44:31 +00:00
|
|
|
|
2020-10-16 18:40:05 +00:00
|
|
|
actions = {
|
|
|
|
'powerdns_reload_zones': {
|
|
|
|
'triggered': True,
|
|
|
|
'command': 'pdns_control rediscover; pdns_control reload',
|
|
|
|
'needs': {
|
|
|
|
'svc_systemd:pdns',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-10-16 15:44:31 +00:00
|
|
|
if node.metadata['powerdns'].get('features', {}).get('bind', False):
|
|
|
|
primary_zones = set()
|
|
|
|
for zone in listdir(zone_path):
|
|
|
|
if not isfile(join(zone_path, zone)) or zone.startswith(".") or zone.startswith("_"):
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
output = check_output(['git', 'log', '-1', '--pretty=%ci', join(zone_path, zone)]).decode('utf-8').strip()
|
|
|
|
serial = datetime.strptime(output, '%Y-%m-%d %H:%M:%S %z').strftime('%y%m%d%H%M')
|
|
|
|
except:
|
|
|
|
serial = datetime.now().strftime('%y%m%d0000')
|
|
|
|
|
|
|
|
primary_zones.add(zone)
|
|
|
|
|
|
|
|
files["/var/lib/powerdns/zones/{}".format(zone)] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'header': ZONE_HEADER.format(serial=serial),
|
|
|
|
'metadata_records': node.metadata.get('powerdns', {}).get('bind-zones', {}).get(zone, {}).get('records', []),
|
|
|
|
},
|
|
|
|
'source': 'bind-zones/{}'.format(zone),
|
2020-10-16 15:59:46 +00:00
|
|
|
'triggers': {
|
2020-10-16 18:40:05 +00:00
|
|
|
'action:powerdns_reload_zones',
|
2020-10-16 15:59:46 +00:00
|
|
|
},
|
2020-10-16 15:44:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 15:59:46 +00:00
|
|
|
files['/etc/powerdns/pdns.d/bind.conf'] = {
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:pdns-backend-bind',
|
|
|
|
},
|
|
|
|
'triggers': {
|
2020-10-16 18:40:05 +00:00
|
|
|
'action:powerdns_reload_zones',
|
2020-10-16 15:59:46 +00:00
|
|
|
},
|
|
|
|
}
|
2020-10-16 17:23:45 +00:00
|
|
|
|
2020-10-16 15:44:31 +00:00
|
|
|
files['/etc/powerdns/named.conf'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'zones': primary_zones,
|
|
|
|
},
|
2020-10-16 15:59:46 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:pdns-backend-bind',
|
|
|
|
},
|
|
|
|
'triggers': {
|
2020-10-16 18:40:05 +00:00
|
|
|
'action:powerdns_reload_zones',
|
2020-10-16 15:59:46 +00:00
|
|
|
},
|
2020-10-16 15:44:31 +00:00
|
|
|
}
|
2020-10-16 17:23:45 +00:00
|
|
|
|
|
|
|
if node.metadata['powerdns'].get('features', {}).get('pgsql', False):
|
|
|
|
files['/etc/powerdns/pdns.d/pgsql.conf'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'password': node.metadata['postgresql']['users']['powerdns']['password'],
|
|
|
|
},
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:pdns-backend-pgsql',
|
|
|
|
},
|
|
|
|
'triggers': {
|
2020-10-16 18:40:05 +00:00
|
|
|
'action:powerdns_reload_zones',
|
2020-10-16 17:23:45 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
files['/etc/powerdns/schema.pgsql.sql'] = {}
|
|
|
|
|
2020-10-16 18:40:05 +00:00
|
|
|
actions['powerdns_load_pgsql_schema'] = {
|
2020-10-17 08:50:21 +00:00
|
|
|
'command': node.metadata['postgresql']['users']['powerdns']['password'].format_into('PGPASSWORD={} psql -h 127.0.0.1 -d powerdns -U powerdns -w < /etc/powerdns/schema.pgsql.sql'),
|
|
|
|
'unless': 'sudo -u postgres psql -d powerdns -c "\dt" | grep domains 2>&1 >/dev/null',
|
2020-10-16 18:40:05 +00:00
|
|
|
'needs': {
|
|
|
|
'bundle:postgresql',
|
|
|
|
'file:/etc/powerdns/schema.pgsql.sql',
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:pdns',
|
|
|
|
},
|
2020-10-16 17:23:45 +00:00
|
|
|
}
|