Automatic import of JSON configuration

Expected behavior:

At boot all .list files are being read in and added to the database, I expect the same behavior for the JSON configuration files

Actual behavior:

JSON files are ignored, hence no config is applied

Steps to reproduce:

Paste the JSON configuration files into /etc/pihole (location where the .list files go) and restart the system/container

Troubleshooting undertaken, and/or other relevant information:

Current fix is using the web interface to upload the configuration via Teleporter, but that requires a manual operation

Additional questions

  • Can the teleporter be used from CLI?
  • Does Pihole always check the .list files at boot and migrate them on changes? Or is there a flag that's being set after the first time the list files were read in and migrated?

Are you referring to Docker only?

Non docker Pi-Hole also works with the list files, but I'm currently using a docker implementation, yes.
Not sure when non-docker Pi-Hole reads the files, probably at boot and when the gravity is updated?

But my issue/feature request is aimed at the new configuration files in json format.
I can export them using teleporter, but I'd like them to be read in automatically as well (For example at a container update or recreate). This was possible using the .list files, but is this already possible with the current json files?

Neither, at least in Pi-hole V5 and later. Domains and adlists are stored in /etc/pihole/gravity.list. This file is static and changes only if you change blocking domains or adlists, or unless you rebuild gravity or refresh the database.

If you refresh the database, the list files are searched in /etc/pihole/migration_backup.

I'd like to move away from using the list files and switch over to the JSON files only, as I assume this is the new format for v5.0, with more information stored in them (comments etc). The teleporter on the webpage allows those json files to be read in, but how would I automate that process from within the container itself, CLI?

What problem do you wish to solve? I'm still a bit confused on the potential benefits of this feature.

I wish to be able to export and import the Pi-Hole configuration (Json is currently the most complete one) without any user interaction. Would it be possible to run (for example the teleporter scripts) from the command line in the container? That way I can automate the export and import.

At first I was under the impression that the json configuration would replace the .list. But the json files are no where to be found inside the container, so I'm assuming the teleporter generates those from the db's, and they're merely ment for manual export and import of the configuration?

I could also just export the db's themself, but that has two downsides: unreadable and uneditable without database management software. So I'd rather stick to the json's.

I think this is what you really want: Be able to run teleporter im/export via cli.

So far, teleporter is the only piece of pihole using the jsons.

For export try pihole -a - t
Looking at the code, I don't see the import function yet.

That's correct.

It is still unclear what problem your are trying to solve.
What's your motivation for automating teleporter imports?

Reason for automatically exporting the teleporter is self explanatory, for backup purposes.
And as I'm running Pi-Hole from within a docker container, I want to be able to automatically import the latest backup export at a new container creation. As I'm running Pi-Hole on multiple devices, the use of volumes isn't satisfactory.

This all worked fine in Pi-Hole v4 as the .list files were read in, but also written to when making changes on the web interface. In Pi-Hole v5 the .list files are only read, and never written to as they are migrated to the database.

So currently the only way of retaining my Pi-Hole configuration in between container recreations is by manually exporting and importing the data.

I completely understand why the change from .list files was made to the db system. But I don't understand why the JSON files can't be used as a base configuration for a new Pi-Hole container. A manual operation is still required to completely configure the container. Meaning that the Pi-Hole container will first start with a 'wrong' configuration (no harm, but still), until the user has accessed the webpage and imported the actual configuration.

A this point I'm beyond maintaining the list files, as I already made changes to my configuration and the only up to date version of my configuration can be acquired as a JSON export.

I hope this clarifies my intentions a bit more?

Partially.

Well, the teleporter is intended to be used for configuration backups (though it may need to be extended to fully support features added with 5.0) .

But commonly, you wouldn't want backups to be applied automatically.
Applying a backup automatically on Pi-hole restart would mean you'd lose all of your manual configuration changes you did since you last started Pi-hole. This could be weeks or months worth of changes. And if there were none, it would be unnecessary and thus ineffective to reapply them at all.

I doubt your focus are backups, hence.

I think you are rather looking for a way to share an existing configuration (edit: or maybe just certain aspects, as /etc/pihole/ wouldn't hold all of Pi-hole's configuration data) among several installations, and to initialise a fresh installation with such a configuration programmatically.

In the past, you achieved this by pasting a set of files into /etc/pihole/.
Did you try to do just that with the gravity.db file?

You'd have to stop and restart Pi-hole before doing so, but if I read you correctly, a restart or even initial start is the situation you are trying to tackle anyways.

From the CLI you can copy the entire gravity database to a storage location. Then in the new container import that database and reload lists. One line of command to save, two lines to import.

For deploying and syncing piholes, see here

Is this for Docker? Just put the data in a volume mount and you can change the containers all you want when ever you want.