#!/usr/bin/env python3 # Update Pi-hole v6 hosts in pihole.toml import re hosts = ''' {% for record in dns_records %} "{{ record.ip }} {{ record.hostname }}.{{ dns_domain }} {{ record.hostname }}", {% endfor %} ''' with open('/etc/pihole/pihole.toml', 'r') as f: content = f.read() # Find and replace hosts array pattern = r'hosts = \[.*?\]' replacement = f'hosts = [{hosts} ]' content = re.sub(pattern, replacement, content, flags=re.DOTALL) with open('/etc/pihole/pihole.toml', 'w') as f: f.write(content) print('Pi-hole DNS hosts updated')