If you want to run Pi-hole on your network but not have the entire family grumble that the internet isn’t working when you need to reboot the machine it’s running on then you’ll need to run two Pi-holes. To run two Pi-holes properly they need to a) be on separate machines (I use my main homelab server and a RaspberryPi) and b) be configured on your client devices appropriately.1
If you’ve got all that working but have been getting annoyed that adding any new service means duplicating manual configuration steps in a clunky Pi-hole web interface then you’ll likely have been searching for some sort of automation to handle it. Fortunately I came across a Terraform provider for Pi-hole that got me most of the way there. I just needed to put together a playbook/plan for it.
So with that. I present STPFMMP (Simple Terraform Playbook For Managing Multiple Pi-holes)
Usage
- Pull the STPFMMP project to your machine
- Copy
domains.json.dist
todomains.json
and edit accordingly - Copy
secret.tfvars.dist
tosecret.tfvars
and edit accordingly - Ensure your Pi-holes have not already got the entries defined (so delete them if they exist)2
terraform init
terraform plan -var-file=secret.tfvars
terraform apply -var-file=secret.tfvars
ProfitBe happy that editing your home network DNS is now not so repetitive/dull/error prone.
Now anytime you want to create or edit or otherwise manage your networks local DNS you can just make changes to the domains.json
file and run apply again. Everything gets put in the right place and you don’t have to go prodding around in the Pi-hole interface.
If you’re using the primary Pi-hole as a DHCP this is actually fairly easy. Add a new file to the
/etc/dnsmasq.d/
called07-pihole-dhcp-dns.conf
and in that file add a line likedhcp-option=6,192.168.100.2,192.168.100.3
(obviously replacing those IP addresses with whatever you’re using). Ensure you restart dnsmasq. If you’re using your router then I’d advise prodding around in whatever setting you have available. Failing that configure your devices manually. ↩︎The terraform provider being used has not yet implemented refresh/import support so the only way to get this to work is to ensure you’re running it on a blank canvas. I ran the
apply
step multiple times so that I could remove values from one Pi-hole instance at a time. ↩︎
Comments