A gitops way to sync two or many PiHoles without having connection between them.
This script synchronizes the following data
- Configuration (web password, dns upstream)
- Local DNS
- DNS Records
- CName Records
- Groups
- Clients
- Adlist
- Domains List (Allow list & Block list)
Does not sync:
- DHCP
Follow steps: https://docs.driverlandia.com/books/pihole/page/sincronizacion-de-varios-pihole
Inside pihole folder (same level that etc-pihole, etc-dnsmasq.d, var-log-pihole) execute this Command
python3 gravity_sync.py -a export
This command will generate the gravity_changes.json
(see the example file). You can specify the name of this file.
Commit this file to git repository (git commit & push), make a pull on the second or third (or N PiHole) and then execute
python3 gravity_sync.py -a import
Execution result of git pull & import command on second PiHole
Arg | Long Argument | Values | Default | Description |
---|---|---|---|---|
-d |
--database |
etc-pihole/gravity.db |
Path and name of gravity database | |
-f |
--file |
gravity_changes.json |
Path of file where write/read export/import changes | |
-a |
--action |
import export |
You need to specify | Action you want to perform |
-ug |
--upgrade-gravity |
y n |
n |
Execute force upgrade IOC after adding adlist |
-cn |
--container-name |
pihole |
Container name of pihole |
For export changes from master to git, you can add this line to cron
*/15 * * * * cd /docker/pihole/ && python3 gravity_sync.py -a export && git add -A && git commit -m "Autoupdate" && git push
For import to secondary PiHoles add this line in cron. Command restartdns reload is for reload DNS if file of local DNS has been updated
*/15 * * * * cd /docker/pihole/ && git pull && docker exec -it pihole /bin/bash pihole restartdns reload && python3 gravity_sync.py -a import
Import and if there's a new adlist added, then force gravity update. Be careful, if you check many times at day some list they will ban you for a few days.
*/15 * * * * cd /docker/pihole/ && git pull && docker exec -it pihole /bin/bash pihole restartdns reload && python3 gravity_sync.py -a import -ug y
If you use this setupvars.conf the password of PiHole web is admin
.
Please change this password!! DON'T USE IN PRODUCTION!
If this project has been useful to you, you can give me a coffee at Paypal