I have two raspberry pis on my network running Pi-hole, but keeping the whitelist and blacklist entries in sync between them was a chore, so I wrote pihole-sync:
It's simple to use: just clone, add details of your devices to settings.py (see the README), then run python3 sync.py. Enjoy!
The changes are applied automatically. The script uses the PHP API, which handles the dnsmasq refresh. (Under the hood, the API is just shelling out to sudo pihole -w and sudo pihole -b - see here.)
Good catch! This was my fault. The script relies on features introduced in Python 3.6, but the latest Raspbian distribution ships with Python 3.5.3. So this script for aiding administration of Raspberry Pis won’t run on an out-of-the-box Raspberry Pi. Doh!
I just pushed a fix to Github. If you do a git pull you should find it now works. Apologies for the confusion!
+1 script works.
sad part: getting another error. It attempts to sync one whitelist entry, then throws an error.
quick fix is defining argument (missed one).
line 95 list_api_arg = ""
python3 sync.py
Adding s3.amazonaws.com to WHITELIST on 192.168.100.100
Traceback (most recent call last):
File "sync.py", line 185, in
sync_lists(hosts)
File "sync.py", line 176, in sync_lists
sync_count = _sync_list(hosts, list_type)
File "sync.py", line 167, in _sync_list
h.add_list_entry(entry, list_type)
File "sync.py", line 95, in add_list_entry
list_api_arg
UnboundLocalError: local variable 'list_api_arg' referenced before assignment
I was able to get your script working with my 2 Pi-holes... but it did not function as I expected when I removed a domain from the whitelist on Pi-hole 1. Is the procedure for removing items from lists to manually remove them from each host? Kind of defeats the purpose of a sync script.
Would you consider editing the script to designate one host as the "primary" and then all other hosts as "secondary?" That way the sync always goes in one direction.