diff --git a/bundles/bind/files/db b/bundles/bind/files/db new file mode 100644 index 0000000..6203c6f --- /dev/null +++ b/bundles/bind/files/db @@ -0,0 +1,17 @@ +$TTL 600 +@ IN SOA ns.sublimity.de. admin.sublimity.de. ( + 2020080302 ;Serial + 1200 ;Refresh + 600 ;Retry + 1209600 ;Expire + 600 ;Negative response caching TTL +) + +% for record in sorted(records, key=lambda r: (r['name'], r['type'], r['value'])): + % for part in (record['value'][i:i+256] for i in range(0, len(record['value']), 255)): +${record['name'].ljust(column_width('name', records))} \ +IN \ +${record['type'].ljust(column_width('type', records))} \ +"${part}" + % endfor +% endfor diff --git a/bundles/bind/files/defaults b/bundles/bind/files/defaults new file mode 100644 index 0000000..9819214 --- /dev/null +++ b/bundles/bind/files/defaults @@ -0,0 +1,2 @@ +RESOLVCONF=no +OPTIONS="-u bind" diff --git a/bundles/bind/files/zonefile b/bundles/bind/files/zonefile deleted file mode 100644 index 2256061..0000000 --- a/bundles/bind/files/zonefile +++ /dev/null @@ -1,12 +0,0 @@ -$TTL 600 -@ IN SOA ns.sublimity.de. admin.sublimity.de. ( - 2020080302 ;Serial - 1200 ;Refresh - 600 ;Retry - 1209600 ;Expire - 600 ;Negative response caching TTL -) - -% for record in records: -${record[0].ljust(max_name)} IN ${record[1].ljust(max_type)} ${record[2]} -% endfor diff --git a/bundles/bind/items.py b/bundles/bind/items.py index adc77e5..2bf07f4 100644 --- a/bundles/bind/items.py +++ b/bundles/bind/items.py @@ -1,8 +1,20 @@ -# for zone, records in node.metadata.get('bind/zones').items(): -# files[f'/var/lib/bind/{zone}'] = { -# 'source': 'zonefile', -# 'content_type': 'mako', -# 'context': { -# 'records': records, -# } -# } +directories['/var/lib/bind'] = { + 'purge': True, +} + +files['/etc/default/bind9'] = { + 'source': 'defaults', +} + +def column_width(column, table): + return max(map(lambda row: len(row[column]), table)) if table else 0 + +for zone, records in node.metadata.get('bind/zones').items(): + files[f'/var/lib/bind/db.{zone}'] = { + 'source': 'db', + 'content_type': 'mako', + 'context': { + 'records': records, + 'column_width': column_width, + } + } diff --git a/bundles/bind/metadata.py b/bundles/bind/metadata.py index a890878..37b3f6f 100644 --- a/bundles/bind/metadata.py +++ b/bundles/bind/metadata.py @@ -38,7 +38,7 @@ def collect_records(metadata): zones\ .setdefault(zone, [])\ .append( - (name, type, value) + {'name': name, 'type': type, 'value': value} ) return {