From 66628635b94a4fe700f1b73e8df7094096b3db25 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Wed, 25 Nov 2026 18:03:07 +0000 Subject: [PATCH] feat(pihole): add the pihole role Installs Pi-hole v6 on Ubuntu noble and resolute by cloning the upstream repository and running its installer unattended, with pihole.toml rendered from pihole_default merged with pihole_overrides. A change to pihole.toml runs the installer's reconfigure mode. Validation runs first under always: the host must be Ubuntu, and the merged settings need a non-empty interface and upstream list and a string password other than the placeholder. pihole_web_password is a required no_log input. Computed values are internal __pihole_ names. Derived from codeberg.org/ansible/pihole (GPL-3.0-only) with Pi-hole FTL comment text (EUPL-1.2): REUSE.toml annotations, the EUPL-1.2 text and NOTICE entries record both. The README roadmap drops pihole. Assisted-by: Claude Code:claude-opus-5-5 --- LICENSES/EUPL-1.2.txt | 190 ++++ NOTICE | 9 +- README.md | 12 +- REUSE.toml | 14 + changelogs/fragments/pihole-role.yml | 8 + roles/pihole/README.md | 79 ++ roles/pihole/defaults/main.yml | 517 +++++++++++ roles/pihole/handlers/main.yml | 15 + roles/pihole/meta/argument_specs.yml | 93 ++ roles/pihole/meta/main.yml | 18 + roles/pihole/tasks/configure.yml | 37 + roles/pihole/tasks/install.yml | 75 ++ roles/pihole/tasks/main.yml | 47 + roles/pihole/tasks/merge-defaults.yml | 24 + roles/pihole/tasks/reconfigure.yml | 17 + roles/pihole/tasks/validate.yml | 55 ++ roles/pihole/templates/pihole.toml.j2 | 1202 +++++++++++++++++++++++++ tests/sanity/ignore-common.txt | 1 + 18 files changed, 2405 insertions(+), 8 deletions(-) create mode 100644 LICENSES/EUPL-1.2.txt create mode 100644 changelogs/fragments/pihole-role.yml create mode 100644 roles/pihole/README.md create mode 100644 roles/pihole/defaults/main.yml create mode 100644 roles/pihole/handlers/main.yml create mode 100644 roles/pihole/meta/argument_specs.yml create mode 100644 roles/pihole/meta/main.yml create mode 100644 roles/pihole/tasks/configure.yml create mode 100644 roles/pihole/tasks/install.yml create mode 100644 roles/pihole/tasks/main.yml create mode 100644 roles/pihole/tasks/merge-defaults.yml create mode 100644 roles/pihole/tasks/reconfigure.yml create mode 100644 roles/pihole/tasks/validate.yml create mode 100644 roles/pihole/templates/pihole.toml.j2 diff --git a/LICENSES/EUPL-1.2.txt b/LICENSES/EUPL-1.2.txt new file mode 100644 index 0000000..6d8cea4 --- /dev/null +++ b/LICENSES/EUPL-1.2.txt @@ -0,0 +1,190 @@ +EUROPEAN UNION PUBLIC LICENCE v. 1.2 +EUPL © the European Union 2007, 2016 + +This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the +terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such +use is covered by a right of the copyright holder of the Work). +The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following +notice immediately following the copyright notice for the Work: + Licensed under the EUPL +or has expressed by any other means his willingness to license under the EUPL. + +1.Definitions +In this Licence, the following terms have the following meaning: +— ‘The Licence’:this Licence. +— ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available +as Source Code and also as Executable Code as the case may be. +— ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or +modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work +required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in +the country mentioned in Article 15. +— ‘The Work’:the Original Work or its Derivative Works. +— ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and +modify. +— ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by +a computer as a program. +— ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence. +— ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to +the creation of a Derivative Work. +— ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the +Licence. +— ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating, +transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential +functionalities at the disposal of any other natural or legal person. + +2.Scope of the rights granted by the Licence +The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for +the duration of copyright vested in the Original Work: +— use the Work in any circumstance and for all usage, +— reproduce the Work, +— modify the Work, and make Derivative Works based upon the Work, +— communicate to the public, including the right to make available or display the Work or copies thereof to the public +and perform publicly, as the case may be, the Work, +— distribute the Work or copies thereof, +— lend and rent the Work or copies thereof, +— sublicense rights in the Work or copies thereof. +Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the +applicable law permits so. +In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed +by law in order to make effective the licence of the economic rights here above listed. +The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the +extent necessary to make use of the rights granted on the Work under this Licence. + +3.Communication of the Source Code +The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as +Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with +each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to +the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to +distribute or communicate the Work. + +4.Limitations on copyright +Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the +exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations +thereto. + +5.Obligations of the Licensee +The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those +obligations are the following: + +Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to +the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the +Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work +to carry prominent notices stating that the Work has been modified and the date of modification. + +Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this +Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless +the Original Work is expressly distributed only under this version of the Licence — for example by communicating +‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the +Work or Derivative Work that alter or restrict the terms of the Licence. + +Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both +the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done +under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed +in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with +his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail. + +Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide +a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available +for as long as the Licensee continues to distribute or communicate the Work. +Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names +of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and +reproducing the content of the copyright notice. + +6.Chain of Authorship +The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or +licensed to him/her and that he/she has the power and authority to grant the Licence. +Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or +licensed to him/her and that he/she has the power and authority to grant the Licence. +Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions +to the Work, under the terms of this Licence. + +7.Disclaimer of Warranty +The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work +and may therefore contain defects or ‘bugs’ inherent to this type of development. +For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind +concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or +errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this +Licence. +This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work. + +8.Disclaimer of Liability +Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be +liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the +Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss +of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, +the Licensor will be liable under statutory product liability laws as far such laws apply to the Work. + +9.Additional agreements +While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services +consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole +responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by +the fact You have accepted any warranty or additional liability. + +10.Acceptance of the Licence +The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window +displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of +applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms +and conditions. +Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You +by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution +or Communication by You of the Work or copies thereof. + +11.Information to the public +In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, +by offering to download the Work from a remote location) the distribution channel or media (for example, a website) +must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence +and the way it may be accessible, concluded, stored and reproduced by the Licensee. + +12.Termination of the Licence +The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms +of the Licence. +Such a termination will not terminate the licences of any person who has received the Work from the Licensee under +the Licence, provided such persons remain in full compliance with the Licence. + +13.Miscellaneous +Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the +Work. +If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or +enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid +and enforceable. +The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of +the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. +New versions of the Licence will be published with a unique version number. +All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take +advantage of the linguistic version of their choice. + +14.Jurisdiction +Without prejudice to specific agreement between parties, +— any litigation resulting from the interpretation of this License, arising between the European Union institutions, +bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice +of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union, +— any litigation arising between other parties and resulting from the interpretation of this License, will be subject to +the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business. + +15.Applicable Law +Without prejudice to specific agreement between parties, +— this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, +resides or has his registered office, +— this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside +a European Union Member State. + + + Appendix + +‘Compatible Licences’ according to Article 5 EUPL are: +— GNU General Public License (GPL) v. 2, v. 3 +— GNU Affero General Public License (AGPL) v. 3 +— Open Software License (OSL) v. 2.1, v. 3.0 +— Eclipse Public License (EPL) v. 1.0 +— CeCILL v. 2.0, v. 2.1 +— Mozilla Public Licence (MPL) v. 2 +— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3 +— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software +— European Union Public Licence (EUPL) v. 1.1, v. 1.2 +— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+). + +The European Commission may update this Appendix to later versions of the above licences without producing +a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the +covered Source Code from exclusive appropriation. +All other changes or additions to this Appendix require the production of a new EUPL version. diff --git a/NOTICE b/NOTICE index 640a045..3aedd09 100644 --- a/NOTICE +++ b/NOTICE @@ -1,10 +1,15 @@ mortis.kamino Ansible Collection Copyright Defame1297 and contributors. Licensed GPL-3.0-or-later (see COPYING). -The GPL-3.0-only file roles/ufw/templates/before.rules.j2 makes the Collection -as a whole distributable under GPL-3.0 only. +Files marked GPL-3.0-only (roles/pihole, roles/ufw/templates/before.rules.j2) +make the Collection as a whole distributable under GPL-3.0 only. This Collection contains third-party material. Each file carries an SPDX header naming its licence; licence texts are in LICENSES/. +- roles/pihole: derived from https://codeberg.org/ansible/pihole by Taha Ahmed + (solarchemist), upstream commit 95a20d4 (GPL-3.0), modified by Defame1297. +- roles/pihole/templates/pihole.toml.j2, roles/pihole/defaults/main.yml: comment + text from Pi-hole FTL v6.2.2/v6.2.3, Copyright Pi-hole, LLC (EUPL-1.2); the + combined work is distributed under GPL-3.0 per EUPL Art. 5. - roles/ufw/templates/before.rules.j2: derived from ufw conf/before.rules, Copyright 2008-2023 Canonical Ltd. (GPL-3.0-only). diff --git a/README.md b/README.md index 6a6abd1..1b70198 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ An Ansible Collection of reusable, hardened roles for a self-hosted home lab: `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, -`sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management`, -plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap). +`pihole`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and +`user_management`, plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap). Status: roles arrive in waves. Release 2.0.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call). @@ -39,7 +39,7 @@ when its own prerequisites (tests, a safe cutover wherever the role already runs Still to come: -- Wave 2: `pve_vm`, `pve_lxc`, `tailscale`, `pihole`. +- Wave 2: `pve_vm`, `pve_lxc`, `tailscale`. - Wave 3: `rke2`, `proxmox_host`. - Later, wave not yet assigned: `opnsense`, `proxmox_firewall`. @@ -49,9 +49,9 @@ Will not be extracted (they serve one lab or install that lab's own tool pins): ## Licence -Licensed GPL-3.0-or-later (see `COPYING`). The GPL-3.0-only file -roles/ufw/templates/before.rules.j2 makes the Collection as a whole -distributable under GPL-3.0 only. Third-party material +Licensed GPL-3.0-or-later (see `COPYING`). Files marked GPL-3.0-only +(roles/pihole, roles/ufw/templates/before.rules.j2) make the Collection as a +whole distributable under GPL-3.0 only. Third-party material keeps its own licence, marked by an SPDX header, with texts in `LICENSES/` and attribution in `NOTICE`. The repository follows the REUSE specification (`reuse lint`). diff --git a/REUSE.toml b/REUSE.toml index 338a662..92466d6 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -20,3 +20,17 @@ path = "roles/ufw/templates/before.rules.j2" precedence = "override" SPDX-FileCopyrightText = "2008-2023 Canonical Ltd." SPDX-License-Identifier = "GPL-3.0-only" + +# Derived from https://codeberg.org/ansible/pihole by Taha Ahmed (solarchemist), commit 95a20d4. +[[annotations]] +path = "roles/pihole/**" +precedence = "override" +SPDX-FileCopyrightText = ["Taha Ahmed (solarchemist)", "Defame1297 and contributors"] +SPDX-License-Identifier = "GPL-3.0-only" + +# The option comments came in via that upstream from Pi-hole FTL (https://github.com/pi-hole/FTL). +[[annotations]] +path = ["roles/pihole/templates/pihole.toml.j2", "roles/pihole/defaults/main.yml"] +precedence = "override" +SPDX-FileCopyrightText = ["Taha Ahmed (solarchemist)", "Pi-hole, LLC", "Defame1297 and contributors"] +SPDX-License-Identifier = "GPL-3.0-only AND EUPL-1.2" diff --git a/changelogs/fragments/pihole-role.yml b/changelogs/fragments/pihole-role.yml new file mode 100644 index 0000000..2fd9c19 --- /dev/null +++ b/changelogs/fragments/pihole-role.yml @@ -0,0 +1,8 @@ +--- +minor_changes: + - >- + pihole - New role. Installs Pi-hole v6 on Ubuntu noble and resolute by cloning the upstream repository and running + its installer unattended, with ``pihole.toml`` rendered from ``pihole_default`` merged with ``pihole_overrides``. + ``pihole_web_password`` is a required secret input, and ``pihole_overrides`` must set ``config.dns.interface``. + A change to ``pihole.toml`` runs the installer's reconfigure mode. Derived from codeberg.org/ansible/pihole + (GPL-3.0-only), with Pi-hole FTL comment text (EUPL-1.2). diff --git a/roles/pihole/README.md b/roles/pihole/README.md new file mode 100644 index 0000000..42e5c17 --- /dev/null +++ b/roles/pihole/README.md @@ -0,0 +1,79 @@ +# pihole + +Installs [Pi-hole](https://pi-hole.net) v6 by cloning the upstream repository and running its installer unattended, with `pihole.toml` rendered by the role from a merged settings dictionary. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth. + +## Supported platforms + +Ubuntu 24.04 (noble) and 26.04 (resolute), the two images the molecule scenario runs on. The role asserts that the host is Ubuntu before any change. It targets Ubuntu only, not Debian/Proxmox hosts: the upstream installer is run on the Ubuntu hosts it is tested on. The package dependencies come from `ansible.builtin.apt`. The host needs outbound access to the upstream Pi-hole repository (`repo.remote` in the merged settings) and to the apt mirrors. + +## Requirements and run order + +- Use it by its fully qualified name, `mortis.kamino.pihole`, in a play that gathers facts: the role reads `ansible_env.HOME` and `ansible_user_id`, and fails at the Ubuntu assert without facts. +- `pihole_web_password` is required (argument spec): a secret of its own, sourced from a vaulted variable. It is needed even when `pihole_overrides` sets the password, because the merge templates all of `pihole_default`, which references it. +- `pihole_overrides` must set `config.dns.interface`, which has no usable default. +- `become` is used for the package, user, file, template and installer tasks. The repository is cloned as the connecting user (`ansible_user_id`). + +## Role variables + +| Variable | Default | Description | +|---|---|---| +| `pihole_web_password` | none (required) | The web/API password, the default of the merged `config.webserver.api.password`. `no_log`. | +| `pihole_overrides` | `{}` | Overrides merged recursively over `pihole_default`. Must set `config.dns.interface`. | +| `pihole_default` | all Pi-hole settings, see `defaults/main.yml` | Every setting rendered into `pihole.toml`. Override keys through `pihole_overrides`, not by redefining it. | +| `pihole_testing` | `false` | Print the merged settings (secrets masked), pause, and on a first install print the installer log. | +| `pihole_testing_timeout` | `5` | Seconds to pause when testing. | +| `pihole_force_install` | `false` | No effect: the install condition ends in `or true`. | +| `pihole_install_script` | the quoted `/automated install/basic-install.sh` | Installer command. | +| `pihole_apt_dependencies` | curl, git, procps, lighttpd-mod-deflate, apt-utils, whiptail, dnsutils, bc, unzip, wget, sudo, netcat-openbsd, cron, iproute2 | apt packages installed first. Overriding replaces the list. | + +`pihole_default` and `pihole_install_script` are not in the argument spec: argument validation templates every listed variable, and their defaults read gathered facts and the merged settings, which do not exist yet when it runs. + +Keys of `pihole_overrides` that the role itself reads: `repo.remote`, `repo.version` (default `v6.4`), `repo.path` (default `~/.cache/pi-hole`), `user` and `group` (default `pihole`), `config.files.database` (its directory receives `pihole.toml`), `config.dns.upstreams` (must stay a non-empty list), `config.dns.interface` (must be a non-empty string) and `config.webserver.api.password` (must stay a string other than `changetoyourownpassword`). Every other key is rendered into `pihole.toml` by the template. + +The upstreams default to `1.1.1.1` and `8.8.8.8`, `config.dns.domain` to `lan` and the password to `pihole_web_password`. Source an overridden password from a vaulted variable. + +## Tags + +The input asserts carry `always` (and `assert`), so they run whatever tags are selected. The merge import carries `default`, `backups-only`, `config-only` and `updates-only`; the installed check (stat and fact) carries `updates-only`; the configuration-directory check and the reconfigure import carry `config-only`. The version fact, configuration and installation tasks carry no tag of their own, so they run only when no tags are selected. + +## Example play + +```yaml +- name: Run Pi-hole + hosts: dns_servers + roles: + - role: mortis.kamino.pihole + vars: + pihole_web_password: "{{ vault_pihole_web_password }}" + pihole_overrides: + config: + dns: + interface: eth0 + upstreams: + - 9.9.9.9 + - 149.112.112.112 +``` + +## Tests + +The `default` molecule scenario runs on noble and resolute. It replaces the upstream repository with a local stub whose installer only logs its arguments and creates the database file, so it tests the merge, the asserts, the user, the rendered `pihole.toml`, the installer sequence (install once, then reconfigure from the handler) and idempotence, not Pi-hole itself: no pihole-FTL service runs, so that the service loaded the configuration is not verified. It runs `check` before the converge (a first-run preview) and after the idempotence run. Negative tests in `verify.yml` cover a host without Ubuntu facts, a missing `pihole_web_password`, an unset interface, empty upstreams, a non-string password and the placeholder password. + +## Notes + +- Idempotent: yes. +- Merge model: the role sets an internal fact to `pihole_default | combine(pihole_overrides | default({}), recursive=True)`. The input is only read, never overwritten, so each run recomputes the merge. Dictionaries are not merged across variable sources, so define `pihole_overrides` in one place only. +- Secrets: the password is hashed twice with SHA-256 in the template (`pwhash`). The merge and both template tasks use `no_log`, and the templates `diff: false`, so a `pihole.toml` change shows no diff. `pihole_testing` masks the web password, app password and TOTP secret in its output. `totp_secret` and `app_password` default to empty strings. +- Install flow: the role creates the `pihole` system user (nologin), the configuration directory and, on first install, `pihole.toml`, because the unattended installer needs it first. It clones `repo.version` and runs the installer with `--unattended` only when `config.files.database` does not exist yet. A change to `pihole.toml` notifies the `reconfigure pihole` handler, which runs the installer with `--reconfigure --unattended`. +- Updates: the role does not upgrade an installed Pi-hole; changing `repo.version` only moves the clone. +- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host where the configuration directory does not exist yet, the `pihole.toml` template tasks are skipped under `--check`, because the directory they write into is not created. +- `misc.readOnly` defaults to `true`, so Pi-hole does not change `pihole.toml` through its API or CLI and the role's rendering stays authoritative. +- The web interface listens on ports 8080 and 8443 by default (`config.webserver.port`), not 80. The role defines no firewall rules. +- The FTL database keeps queries for `config.database.maxDBdays` days (default 91) and can grow large; lower that key to limit it. +- Double-hash a password by hand from stdin, for comparison with `pwhash`: + + ``` + echo -n somelongandsecretstringofyourown | sha256sum | awk '{printf "%s",$1 }' | sha256sum + ``` + +- Upstream references, not verified by this repository: https://github.com/pi-hole/pi-hole, https://docs.pi-hole.net/ftldns/configfile, https://github.com/pi-hole/pi-hole/issues/5283, https://discourse.pi-hole.net/t/support-writing-to-pihole-toml-directly/70522. +- `no_log` is used on every task that carries the password; see Secrets above. diff --git a/roles/pihole/defaults/main.yml b/roles/pihole/defaults/main.yml new file mode 100644 index 0000000..8b3ee0a --- /dev/null +++ b/roles/pihole/defaults/main.yml @@ -0,0 +1,517 @@ +--- +# SPDX-License-Identifier: GPL-3.0-only AND EUPL-1.2 +# Derived from https://codeberg.org/ansible/pihole by Taha Ahmed (solarchemist), +# modified by Defame1297. The option comments came in via that upstream from +# Pi-hole FTL v6.2.2/v6.2.3 (Copyright Pi-hole, LLC, EUPL-1.2); see NOTICE. + +pihole_default: + repo: + remote: "https://github.com/pi-hole/pi-hole.git" + # use "version: latest" to get the latest *release*, or specify a version + # to install, e.g., "version: 'v6.1.4'" + version: "v6.4" + # I don't like using /tmp because it requires running git as root + # most suitable "tmp"-like path under user's HOME is ~/.cache/ I guess + path: "{{ ansible_env.HOME }}/.cache/pi-hole" + gh_slug: "pi-hole/pi-hole" + user: pihole + group: pihole + # configure /etc/pihole/pihole.toml + # I chose to configure it this way because neither lineinfile nor blockinfile modules + # are suitable for handling TOML files + # https://stackoverflow.com/questions/79673679/ansible-lineinfile-and-replace-modules-attempting-to-configure-toml-txt-file + config: + dns: + # array of IP addresses and/or hostnames, optionally with a port (#...) + # dns_servers: + upstreams: + - "1.1.1.1" + - "8.8.8.8" + # Use this option to control deep CNAME inspection. Disabling it might be beneficial + # for very low-end devices + CNAMEdeepInspect: true + blockESNI: true + EDNS0ECS: true + # Should FTL hide queries made by localhost? + ignoreLocalhost: false + # Should FTL analyze and show internally generated DNSSEC queries? + showDNSSEC: true + # Should FTL analyze *only* A and AAAA queries? + analyzeOnlyAandAAAA: false + # Changing this setting causes FTL to restart. + # Possible values are "NONE", "HOSTNAME", "HOSTNAMEFQDN", or "PI.HOLE" + piholePTR: "PI.HOLE" + # How should FTL handle queries when the gravity database is not available? + # Possible values are: "BLOCK", "ALLOW", "REFUSE", "DROP" + replyWhenBusy: "DROP" + blockTTL: 2 + # List of custom DNS records + hosts: [] + # If set, A and AAAA queries for plain names, without dots or domain parts, are never + # forwarded to upstream nameservers + # Is true a better default (for Unbound)? # https://github.com/community-scripts/ProxmoxVE/discussions/2508 + domainNeeded: false + # If set, the domain is added to simple names (without a period) in /etc/hosts in the + # same way as for DHCP-derived names + # Is true a better default (for Unbound)? # https://github.com/community-scripts/ProxmoxVE/discussions/2508 + expandHosts: false + # The DNS domain used by your Pi-hole. + # You can disable setting a domain by setting this option to an empty string. + domain: "lan" + # Should all reverse lookups for private IP ranges (i.e., 192.168.x.y, etc) which are + # not found in /etc/hosts or the DHCP leases file be answered with "no such domain" + # rather than being forwarded upstream? + bogusPriv: true + # Validate DNS replies using DNSSEC? + dnssec: false + # Interface to use for DNS (see also dnsmasq.listening.mode) and DHCP (if enabled) + # Host-specific: empty placeholder, the role fails until it is set through + # pihole_overrides (see tasks/validate.yml). + interface: "" + # Add A, AAAA and PTR records to the DNS. + hostRecord: "" + # Pi-hole interface listening modes + # Possible values are: LOCAL, SINGLE, BIND, ALL, NONE + listeningMode: "LOCAL" + # Log DNS queries and replies to pihole.log + queryLogging: true + cnameRecords: [] + # Port used by the DNS server + port: 53 + # Reverse server (former also called "conditional forwarding") feature + # Array of reverse servers each one in one of the following forms: + # ",[/],[#][,]" + revServers: [] + # [dns.cache] + cache: + # Cache size of the DNS server. Note that expiring cache entries naturally make room + # for new insertions over time. Setting this number too high will have an adverse + # effect as not only more space is needed, but also lookup speed gets degraded in the + # 10,000+ range. dnsmasq may issue a warning when you go beyond 10,000+ cache entries. + size: 10000 + # Query cache optimizer: If a DNS name exists in the cache, but its time-to-live has + # expired only recently, the data will be used anyway (a refreshing from upstream is + # triggered). This can improve DNS query delays especially over unreliable Internet + # connections. + optimizer: 3600 + # This setting allows you to specify the TTL used for queries blocked upstream. Once + # the TTL expires, the query will be forwarded to the upstream server again to check + # if the block is still valid. Defaults to caching for one day (86400 seconds). + upstreamBlockedTTL: 86400 + # [dns.blocking] + blocking: + # Should FTL block queries? + active: true + # How should FTL reply to blocked queries? + # Possible values are: NULL, IP_NODATA_AAAA, IP, NX, NODATA + mode: "NULL" + # Should FTL enrich blocked replies with EDNS0 information? + # Possible values are: "NONE", "CODE", "TEXT" + edns: "TEXT" + # [dns.specialDomains] + specialDomains: + # Should Pi-hole always reply with NXDOMAIN to A and AAAA queries of + # use-application-dns.net to disable Firefox automatic DNS-over-HTTP? + mozillaCanary: true + # Should Pi-hole always reply with NXDOMAIN to A and AAAA queries of mask.icloud.com + # and mask-h2.icloud.com to disable Apple's iCloud Private Relay to prevent Apple + # devices from bypassing Pi-hole? + iCloudPrivateRelay: true + # Should Pi-hole always reply with NODATA to all queries to zone resolver.arpa to + # prevent devices from bypassing Pi-hole using Discovery of Designated Resolvers? + designatedResolver: true + reply: + # [dns.reply.host] + host: + # Use a specific IPv4 address for the Pi-hole host? + force4: false + # Custom IPv4 address for the Pi-hole host + IPv4: "" + # Use a specific IPv6 address for the Pi-hole host? + force6: false + # Custom IPv6 address for the Pi-hole host + IPv6: "" + # [dns.reply.blocking] + blocking: + # Use a specific IPv4 address in IP blocking mode? + force4: false + # Custom IPv4 address for IP blocking mode + IPv4: "" + # Use a specific IPv6 address in IP blocking mode? + force6: false + # Custom IPv6 address for IP blocking mode + IPv6: "" + # [dns.rateLimit] + rateLimit: + # Rate-limited queries are answered with a REFUSED reply and not further processed by FTL. + count: 1000 + # ... in the set interval before rate-limiting? + interval: 60 + # [dhcp] + dhcp: + # Is the embedded DHCP server enabled? + active: false + # Start address of the DHCP address pool + start: "" + # End address of the DHCP address pool + end: "" + # Address of the gateway to be used (typically the address of your router) + router: "" + # The netmask used by your Pi-hole. + netmask: "" + # If the lease time is given, then leases will be given for that length of time. + leaseTime: "" + # Should Pi-hole make an attempt to also satisfy IPv6 address requests + ipv6: false + # Enable DHCPv4 Rapid Commit Option specified in RFC 4039. + rapidCommit: false + # Advertise DNS server multiple times to clients. + multiDNS: false + # Enable logging for DHCP. + logging: false + # Ignore unknown DHCP clients. + ignoreUnknownClients: false + # Per host parameters for the DHCP server. + hosts: [] + ntp: + # [ntp.ipv4] + ipv4: + # Should FTL act as network time protocol (NTP) server (IPv4)? + active: false + # IPv4 address to listen on for NTP requests + address: "" + # [ntp.ipv6] + ipv6: + # Should FTL act as network time protocol (NTP) server (IPv6)? + active: false + address: "" + # [ntp.sync] + sync: + # Should FTL try to synchronize the system time with an upstream NTP server? + active: false + # NTP upstream server to sync with, e.g., "pool.ntp.org". Note that the NTP server + # should be located as close as possible to you in order to minimize the time offset + # possibly introduced by different routing paths. + # http://www.svl2.ntp.se + # https://www.cyberinfo.se/arkiv/tidssynkronisering-med-ntp + # server: "se.pool.ntp.org" + server: "sth2.ntp.se" + # Interval in seconds between successive synchronization attempts with the NTP server + interval: 3600 + # Number of NTP syncs to perform and average before updating the system time + count: 8 + # [ntp.sync.rtc] + rtc: + # Should FTL update a real-time clock (RTC) if available? + set: false + # Path to the RTC device to update. Leave empty for auto-discovery + device: "" + # Should the RTC be set to UTC? + utc: true + # [resolver] + resolver: + # Should FTL try to resolve IPv4 addresses to hostnames? + resolveIPv4: true + # Should FTL try to resolve IPv6 addresses to hostnames? + resolveIPv6: true + # Control whether FTL should use the fallback option to try to obtain client names from + # checking the network table. This behavior can be disabled with this option. + networkNames: true + # With this option, you can change how (and if) hourly PTR requests are made to check + # for changes in client and upstream server hostnames. + # Possible values are: "IPV4_ONLY", "ALL", "UNKNOWN", "NONE" + refreshNames: "IPV4_ONLY" + # [database] + database: + # Should FTL load information from the database on startup to be aware of the most + # recent history? + DBimport: true + # How long should queries be stored in the database [days]? + # Setting this value to 0 will disable the database. + maxDBdays: 91 + # How often do we store queries in FTL's database [seconds]? + DBinterval: 60 + # Should FTL enable Write-Ahead Log (WAL) mode for the on-disk query database + # (configured via files.database)? It is recommended to leave this setting enabled + # for performance reasons. + useWAL: true + # [database.network] + network: + # Should FTL analyze the local ARP cache? When disabled, client identification and the + # network table will stop working reliably. + parseARPcache: true + # How long should IP addresses be kept in the network_addresses table [days]? IP + # addresses (and associated host names) older than the specified number of days are + # removed to avoid dead entries in the network overview table. + # looks like it should be set to the same value as database.maxDBdays + expire: 91 + # [webserver] + webserver: + # On which domain is the web interface served? + domain: "pi.hole" + # Webserver access control list (ACL) allowing for restrictions to be put on the list + # of IP addresses which have access to the web server. + acl: "" + # Ports to be used by the webserver. Comma-separated list of ports to listen on. + # I want to make it easier on myself so set to port 80 on all interfaces for both IPv4 and IPv6 + # note that this is different from Pi-Hole's default "80o,443os,[::]:80o,[::]:443os" + # port: "80,[::]:80" # this gives the lighttpd landing page and no Pi-Hole web UI + # port: "80o,443os,[::]:80o,[::]:443os" # ditto + # for some reason this works but not the variations above + port: "8080o,8443os,[::]:8080o,[::]:8443os" + # Maximum number of worker threads allowed. + threads: 50 + # Additional HTTP headers added to the web server responses. + headers: + - "X-DNS-Prefetch-Control: off" + - "Content-Security-Policy: default-src 'self' 'unsafe-inline';" + - "X-Frame-Options: DENY" + - "X-XSS-Protection: 0" + - "X-Content-Type-Options: nosniff" + - "Referrer-Policy: strict-origin-when-cross-origin" + # Should the web server serve all files in webserver.paths.webroot directory? + serve_all: false + # [webserver.session] + session: + # Session timeout in seconds. + # This option may also be used to make logins persistent for long times. + timeout: 1800 + # Should Pi-hole backup and restore sessions from the database? + restore: true + # [webserver.tls] + tls: + # Path to the TLS (SSL) certificate file. + cert: "/etc/pihole/tls.pem" + # [webserver.paths] + paths: + # Server root on the host + webroot: "/var/www/html" + # Sub-directory of the root containing the web interface + webhome: "/admin/" + # Prefix where the web interface is served + prefix: "" + # [webserver.interface] + interface: + # Should the web interface use the boxed layout? + boxed: true + # Theme used by the Pi-hole web interface + # Possible values are: "default-auto", "default-light", "default-dark", "default-darker", + # "high-contrast", "high-contrast-dark", "lcars" (Star Trek LCARS) + theme: "default-auto" + # [webserver.api] + api: + # Number of concurrent sessions allowed for the API. + max_sessions: 16 + # Should FTL prettify the API output (add extra spaces, newlines and indentation)? + prettyJSON: false + # API password hash (you set password, hash is generated in Jinja template) + password: "{{ pihole_web_password }}" + # Pi-hole 2FA TOTP secret. + totp_secret: "" + # Pi-hole application password (to circumvent 2FA for legacy 3rd-party services) + app_password: "" + # Should application password API sessions be allowed to modify config settings? + app_sudo: false + # Should FTL create a temporary CLI password? This password is stored in clear in + # /etc/pihole and can be used by the CLI (pihole ... commands) to authenticate + # against the API. + cli_pw: true + # Array of clients to be excluded from certain API responses (regex), + # e.g., the Top Clients or Query Log + excludeClients: [] + # Array of domains to be excluded from certain API responses (regex), + # e.g., the Top Clients or Query Log + excludeDomains: [] + # How much history should be imported from the database and returned by the API + # [seconds]? (max 24*60*60 = 86400) + maxHistory: 86400 + # Up to how many clients should be returned in the activity graph endpoint + # (/api/history/clients)? + # This setting can be overwritten at run-time using the parameter N. Setting this to 0 + # will always send all clients. Be aware that this may be challenging for the GUI if + # you have many (think > 1.000 clients) in your network + maxClients: 0 # default 10 + # How should the API compute the most active clients? + client_history_global_max: true + # Allow destructive API calls (e.g. restart DNS server, flush logs, ...) + allow_destructive: true + # [webserver.api.temp] + temp: + # Which upper temperature limit should be used by Pi-hole? + limit: "60.000000" + # Which temperature unit should be used for temperatures processed by FTL? + unit: "C" + # [files] + files: + # The file which contains the PID of FTL's main process. + pid: "/run/pihole-FTL.pid" + # The location of FTL's long-term database + database: "/etc/pihole/pihole-FTL.db" + # The location of Pi-hole's gravity database + gravity: "/etc/pihole/gravity.db" + # A temporary directory where Pi-hole can store files during gravity updates. + gravity_tmp: "/tmp" + # The database containing MAC -> Vendor information for the network table + macvendor: "/etc/pihole/macvendor.db" + # An optional file containing a pcap capture of the network traffic. + pcap: "" + # [files.log] + log: + # The location of FTL's log file + ftl: "/var/log/pihole/FTL.log" + # The log file used by the embedded dnsmasq DNS server + dnsmasq: "/var/log/pihole/pihole.log" + # The log file used by the webserver + webserver: "/var/log/pihole/webserver.log" + # [misc] + misc: + # Privacy levels in Pi-Hole statistics + # Changing this setting will trigger a restart of FTL + # - 0: don't hide anything + # - 1: hide domains + # - 2: hide domains and clients + # - 3: anonymize everything + privacylevel: 1 + delay_startup: 0 + # Set niceness of pihole-FTL. Defaults to -10 and can be disabled altogether by setting + # a value of -999. + nice: -10 + addr2line: true + # Should FTL load additional dnsmasq configuration files from /etc/dnsmasq.d/? + etc_dnsmasq_d: false + # Either enable misc.etc_dnsmasq_d to restore the "old" behaviour, or if + # you have only a few lines you can add them directly to the misc.dnsmasq_lines + # setting instead. https://discourse.pi-hole.net/t/v6-post-release-fixes-and-findings/76480 + dnsmasq_lines: + # maximum number of concurrent DNS queries, 150 by default + # https://discourse.pi-hole.net/t/ resolved-maximum-number-of-concurrent-dns-queries-reached/60970 + # https://discourse.pi-hole.net/t/maximum-number-of-concurrent-dns-queries-reached/51804 + - "dns-forward-max=150" + # Log additional information about queries and replies to pihole.log + extraLogging: false + # Put configuration into read-only mode. This will prevent any changes to the + # configuration file via the API or CLI. This setting useful when a configuration is + # to be forced/modified by some third-party application (like infrastructure-as-code + # providers) and should not be changed by any means. + # This setting is critical to allow this role to configure pihole.toml reliably + # https://discourse.pi-hole.net/t/support-writing-to-pihole-toml-directly/70522 + # default False + readOnly: true + # [misc.check] + check: + # Have FTL regularly check system load and warn about excessive load if + # the 15 minute system load average exceeds the number of cores? + load: true + shmem: 90 + # warn if disk usage exceeds this percentage (set to zero to disable) + disk: 90 + # [debug] + debug: + # Print debugging information about database actions. + database: false + # Prints a list of the detected interfaces on the startup of pihole-FTL. + networking: false + # Print information about shared memory locks. + locks: false + # Print extensive query information (domains, types, replies, etc.). + queries: false + # Print flags of queries received by the DNS hooks. Only effective when DEBUG_QUERIES + # is enabled as well. + flags: false + # Print information about shared memory buffers. + shmem: false + # Print information about garbage collection + gc: false + # Print information about ARP table processing + arp: false + # Controls if FTLDNS should print extended details about regex matching into FTL.log. + regex: false + # Print extra debugging information concerning API calls. + api: false + # Print extra debugging information about TLS connections. + tls: false + # Print information about overTime memory operations, such as initializing or moving + # overTime slots. + overtime: false + # Print information about status changes for individual queries. + status: false + # Print information about capabilities granted to the pihole-FTL process. + caps: false + # Print information about DNSSEC activity + dnssec: false + # FTL uses dynamically allocated vectors for various tasks. + vectors: false + # Extensive information about hostname resolution like which DNS servers are used in + # the first and second hostname resolving tries (only affecting internally generated + # PTR queries). + resolver: false + # Print debugging information about received EDNS(0) data. + edns0: false + # Log various important client events such as change of interface (e.g., client + # switching from WiFi to wired or VPN connection), as well as extensive reporting + # about how clients were assigned to its groups. + clients: false + # Log information related to alias-client processing. + aliasclients: false + # Log information regarding FTL's embedded event handling queue. + events: false + # Log information about script helpers, e.g., due to dhcp-script. + helper: false + # Print config parsing details + config: false + # Debug monitoring of /etc/pihole filesystem events + inotify: false + # Debug monitoring of the webserver (CivetWeb) events + webserver: false + # Temporary flag that may print additional information. + extra: false + # Reserved debug flag + reserved: false + # Print information about NTP synchronization + ntp: false + # Print information about netlink communication and parsing + netlink: false + # Set all debug flags at once. This is a convenience option to enable all debug flags + # at once. Note that this option is not persistent, setting it to true will enable all + # *remaining* debug flags but unsetting it will disable *all* debug flags. + all: false + + +# Merged recursively over pihole_default. config.dns.interface must be set here. +pihole_overrides: {} + +# set pihole_testing to true to enable debug messages +# easiest via --extra-vars "{pihole_testing: true}" +# the web password, app password and TOTP secret are masked in that output +pihole_testing: false +pihole_testing_timeout: 5 + +# no effect: the install condition ends in "or true" +pihole_force_install: false + +# path to Pi-Hole's automated install script +# supports the "--unattended" flag +# NOTE the inner quotes are important since path contains a space +# Lazy: reads __pihole_effective.repo.path, which tasks/merge-defaults.yml sets in the role. +pihole_install_script: "'{{ __pihole_effective.repo.path }}/automated install/basic-install.sh'" + +# available on Ubuntu noble and resolute +pihole_apt_dependencies: + - curl # command line tool for transferring data with URL syntax + - git # fast, scalable, distributed revision control system + - procps # /proc file system utilities + - lighttpd-mod-deflate # fast webserver with minimal memory footprint + - apt-utils # package management related utility programs + - whiptail # Displays user-friendly dialog boxes from shell scripts + # dropped because of incompatibility with RPi lightdm desktop environment + # which should not affect Ubuntu, but since I have not tested that specifically + # and since this package is not critical, safer to just drop it + # - dhcpcd5 # DHCPv4, IPv6RA and DHCPv6 client with IPv4LL support + - dnsutils # Transitional package for bind9-dnsutils + - bc # GNU bc arbitrary precision calculator language + - unzip # De-archiver for .zip files + - wget # retrieves files from the web + - sudo # Provide limited super user privileges to specific users + - netcat-openbsd # TCP/IP swiss army knife + - cron # process scheduling daemon + - iproute2 # networking and traffic control tools diff --git a/roles/pihole/handlers/main.yml b/roles/pihole/handlers/main.yml new file mode 100644 index 0000000..edcda22 --- /dev/null +++ b/roles/pihole/handlers/main.yml @@ -0,0 +1,15 @@ +--- + +# Rather than restarting the systemd job, use pihole's builtin reconfig script. +# When you run "pihole -r", a TUI window "Existing Install Detected!" lets you +# select either +# + Repair: This will retain existing settings +# + Reconfigure: Resets Pi-hole and allows re-selecting settings +# https://old.reddit.com/r/pihole/comments/m7nx5w/run_pihole_r_unattended +# It looks to me like "--reconfigure --unattended" and "--repair --unattended" both +# perform the same tasks. +- name: Reconfigure Pi-Hole subsystems + become: true + ansible.builtin.command: "{{ pihole_install_script }} --reconfigure --unattended" + listen: reconfigure pihole + changed_when: true diff --git a/roles/pihole/meta/argument_specs.yml b/roles/pihole/meta/argument_specs.yml new file mode 100644 index 0000000..e27e2ef --- /dev/null +++ b/roles/pihole/meta/argument_specs.yml @@ -0,0 +1,93 @@ +--- +argument_specs: + main: + short_description: Install and configure Pi-hole from the upstream repository + description: + - >- + Asserts an Ubuntu host and the merged settings, merges the C(pihole_overrides) dictionary over + C(pihole_default), installs the apt dependencies, creates the C(pihole) system user, renders C(pihole.toml), + clones the upstream repository, runs its installer in unattended mode on first install, and runs the + installer's reconfigure mode when C(pihole.toml) changes. + - >- + The configuration contract is a single dictionary, C(pihole_overrides), whose keys are merged recursively + over C(pihole_default) in C(defaults/main.yml). The spec types it as a dictionary only, because sub-options + would reject every key it does not list. The merged result is an internal fact and never overwrites the + input. The role fails unless the merged C(config.dns.upstreams) is a non-empty list, C(config.dns.interface) + is a non-empty string and C(config.webserver.api.password) is a string other than + C(changetoyourownpassword). + - >- + C(pihole_default) (every setting rendered into C(pihole.toml)) and C(pihole_install_script) (the quoted + installer path under C(repo.path)) are role defaults deliberately not listed here: argument validation + templates every listed variable, and their defaults read gathered facts and the merged settings, which do + not exist yet when it runs. Override settings through C(pihole_overrides) instead. + options: + pihole_web_password: + type: raw + required: true + no_log: true + description: + - >- + The Pi-hole web interface and API password, the default of the merged + C(config.webserver.api.password). A secret: source it from a vaulted variable. Required even when + C(pihole_overrides) sets the password, because the merge templates the whole of C(pihole_default), + which references it. + - The rendered C(pihole.toml) holds it hashed twice with SHA-256 (C(pwhash)). + pihole_overrides: + type: dict + default: {} + no_log: true + description: + - >- + Overrides merged recursively over C(pihole_default). Specify only the keys to change. Define the whole + dictionary in one place, because a dictionary set in two variable sources is not merged and the + higher-precedence one wins. + - >- + C(config.dns.interface) must be set (string, for example C(eth0)): its default is an empty placeholder + and the role fails until it is set. C(config.dns.upstreams) (list of IP addresses or hostnames, + optionally with C(#port)) must stay non-empty. C(config.webserver.api.password) must stay a string. + C(config.webserver.api.totp_secret) and C(config.webserver.api.app_password) are also credentials. + - >- + Other keys the tasks read are C(repo.remote), C(repo.version) (a tag, default C(v6.4)), C(repo.path) + (default C(~/.cache/pi-hole) of the connecting user), C(user), C(group) (both default C(pihole)) and + C(config.files.database) (its directory receives C(pihole.toml)). Every other key is rendered into + C(pihole.toml). + pihole_testing: + type: bool + default: false + description: + - >- + When true the role prints the merged settings with the web password, app password and TOTP secret + masked, pauses C(pihole_testing_timeout) seconds, and on a first install reads and prints the installer + log. + pihole_testing_timeout: + type: int + default: 5 + description: + - Seconds to pause after the merge result is printed. Only used when C(pihole_testing) is true. + pihole_force_install: + type: bool + default: false + description: + - >- + No effect: the install task condition ends in C(or true). Whether the installer runs depends only on + C(config.files.database) not existing yet. + pihole_apt_dependencies: + type: list + elements: str + default: + - curl + - git + - procps + - lighttpd-mod-deflate + - apt-utils + - whiptail + - dnsutils + - bc + - unzip + - wget + - sudo + - netcat-openbsd + - cron + - iproute2 + description: + - apt packages installed before the clone. Overriding replaces the whole list. diff --git a/roles/pihole/meta/main.yml b/roles/pihole/meta/main.yml new file mode 100644 index 0000000..3565700 --- /dev/null +++ b/roles/pihole/meta/main.yml @@ -0,0 +1,18 @@ +--- +galaxy_info: + role_name: pihole + namespace: mortis + author: Taha Ahmed (solarchemist), modified by Defame1297 + license: GPL-3.0-only AND EUPL-1.2 + description: Install and configure Pi-hole v6 from the upstream repository in unattended mode, rendering pihole.toml from a merged settings dict. + min_ansible_version: "2.22" + platforms: + - name: Ubuntu + versions: + - noble + - resolute + galaxy_tags: + - pihole + - dns + - adblock +dependencies: [] diff --git a/roles/pihole/tasks/configure.yml b/roles/pihole/tasks/configure.yml new file mode 100644 index 0000000..5ae3515 --- /dev/null +++ b/roles/pihole/tasks/configure.yml @@ -0,0 +1,37 @@ +--- +# For the unattended install to work as intended (i.e., unattended) pihole.toml must be in +# place *before* the installer runs, so the role creates the pihole user and group itself. + +- name: Create system user and group (nologin shell) for {{ __pihole_effective.user }} + become: true + ansible.builtin.user: + name: "{{ __pihole_effective.user }}" + state: present + system: true + shell: /usr/sbin/nologin + +# this task requires the __pihole_effective.user user/group to exist, fails otherwise +- name: Create Pi-Hole configuration directory + become: true + ansible.builtin.file: + name: "{{ __pihole_effective.config.files.database | dirname }}" + state: directory + owner: "{{ __pihole_effective.user }}" + group: "{{ __pihole_effective.group }}" + mode: '0755' + +- name: Prepare Pi-Hole configuration (first-time installation) + become: true + ansible.builtin.template: + src: pihole.toml.j2 + dest: "{{ __pihole_effective.config.files.database | dirname }}/pihole.toml" + owner: "{{ __pihole_effective.user }}" + group: "{{ __pihole_effective.group }}" + mode: '0644' + when: + - not (__pihole_installed | bool) + - not ansible_check_mode or __pihole_config_dir.stat.exists + notify: reconfigure pihole + # the rendered file holds the password hashes and the TOTP secret + no_log: true + diff: false diff --git a/roles/pihole/tasks/install.yml b/roles/pihole/tasks/install.yml new file mode 100644 index 0000000..8ce83fe --- /dev/null +++ b/roles/pihole/tasks/install.yml @@ -0,0 +1,75 @@ +--- + +# Here I use "dependencies" in a loosely defined fashion +# most of these packages would already be expected to be installed on any Ubuntu system +# but, does not hurt to be thorough +- name: Install dependencies (apt packages) + become: true + ansible.builtin.apt: + name: "{{ pihole_apt_dependencies }}" + state: present + +# https://github.com/gsemet/ansible-rpi-pihole/blob/master/roles/pi/tasks/main.yml +# https://gist.github.com/bendews/e09edfc60e581ec4c686c4b70297f543 +# https://github.com/Freekers/automated-pihole/blob/master/playbook.yml + +# After reading up a little, it seems clear that the regular Pi-Hole +# install script will not work with Ansible by default. +# And in several places, I've seen the pihole devs state thay they don't intend +# to support Ansible playbooks. Fair enough. I've found suggested work-arounds: +# https://github.com/drew-kun/ansible-pihole/blob/master/tasks/install.yml +# https://discourse.pi-hole.net/t/automated-installation-enhancements-and-fixes/28746 +# https://github.com/pi-hole/pi-hole/pull/3195 + +- name: "Clone the Pi-Hole repo" + ansible.builtin.git: + repo: "{{ __pihole_effective.repo.remote }}" + dest: "{{ __pihole_effective.repo.path }}" + version: "{{ __pihole_version }}" + become: true + become_user: "{{ ansible_user_id }}" + register: __pihole_repo + + +# what happens if we run the install script with a pre-existing pihole on the system? +# is it overwritten without complaints from the installer? +# what if the repo has an older version than the installed pihole? +# would it perhaps by easiest to never allow install script to run if pihole is already installed? +# on my machine the install script produced a never-ending output of "y" lines immediately after +# successfully restarting the pihole-FTL service (if output was printed to file it quickly +# filled the available disk space). Did this happen because Pi-Hole was already installed? +- name: Run Pi-Hole installation script in unattended mode + when: + - (__pihole_repo.changed | bool) or (pihole_force_install | bool) or true + # but not if pihole is already installed, in that case let the updater do its job + - not (__pihole_installed | bool) + block: + + # the unattended install only works if pihole.toml already exists (configure.yml) + # debug tip: keep track of the install progress by tailing the log-file on the host in question + - name: Run Pi-Hole installation script + become: true + ansible.builtin.shell: > + {{ pihole_install_script }} --unattended >> + {{ __pihole_effective.repo.path }}/pihole_install.log + changed_when: true + + # can we create a task that tails -f the log file and then quits (continues to next task) + # once no new tail output for X seconds? + # https://stackoverflow.com/questions/33663357/how-to-continuously-tail-remote-files-using-ansible + # https://github.com/ansible/ansible/issues/4870 + # https://github.com/ansible/ansible/issues/3887 + # https://github.com/ansible/proposals/issues/92 + # Perhaps in lieu of tailing we could simply print pihole_install.log in the next task? + - name: Ingest the Pi-Hole install log file + ansible.builtin.slurp: + src: "{{ __pihole_effective.repo.path }}/pihole_install.log" + register: __pihole_install_log + when: pihole_testing | bool + + # https://www.shellhacks.com/ansible-cat-file-print-read-file-content + - name: Display the install log + ansible.builtin.debug: + msg: "{{ __pihole_install_log.content | b64decode }}" + when: pihole_testing | bool + # END OF BLOCK diff --git a/roles/pihole/tasks/main.yml b/roles/pihole/tasks/main.yml new file mode 100644 index 0000000..0fd3994 --- /dev/null +++ b/roles/pihole/tasks/main.yml @@ -0,0 +1,47 @@ +--- +# Validation first, under always, so a bad input fails before any change whatever tags the +# run selects. +- name: Validate the role inputs + ansible.builtin.import_tasks: validate.yml + tags: [always, assert] + +- name: Merge configuration defaults + ansible.builtin.import_tasks: merge-defaults.yml + tags: + - default + - backups-only + - config-only + - updates-only + +- name: Set Pi-Hole version variable + ansible.builtin.set_fact: + __pihole_version: "{{ __pihole_effective.repo.version }}" + +- name: Check if Pi-Hole is already installed + ansible.builtin.stat: + path: "{{ __pihole_effective.config.files.database }}" + register: __pihole_database + tags: updates-only + +- name: Set Pi-Hole installation status + ansible.builtin.set_fact: + __pihole_installed: "{{ __pihole_database.stat.exists | default(false) }}" + tags: updates-only + +# Read by the template tasks: under --check the directory is not created, so on a first run +# there is no directory to render pihole.toml into. +- name: Check whether the Pi-Hole configuration directory exists + ansible.builtin.stat: + path: "{{ __pihole_effective.config.files.database | dirname }}" + register: __pihole_config_dir + tags: config-only + +- name: Configure Pi-Hole + ansible.builtin.import_tasks: configure.yml + +- name: Install Pi-Hole + ansible.builtin.import_tasks: install.yml + +- name: Reconfigure Pi-Hole + ansible.builtin.import_tasks: reconfigure.yml + tags: config-only diff --git a/roles/pihole/tasks/merge-defaults.yml b/roles/pihole/tasks/merge-defaults.yml new file mode 100644 index 0000000..73e7929 --- /dev/null +++ b/roles/pihole/tasks/merge-defaults.yml @@ -0,0 +1,24 @@ +--- +# "pihole_overrides" is only read here: the merged result goes into the fact +# "__pihole_effective", so the input is never overwritten and every run recomputes the merge. +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/combine_filter.html +- name: Merge overrides over the default variable + tags: default + ansible.builtin.set_fact: + __pihole_effective: "{{ pihole_default | combine(pihole_overrides | default({}), recursive=True) }}" + # the merged settings hold the web password + no_log: true + +# the web password, app password and TOTP secret are masked so the dump is +# safe to paste into an issue or leave in CI logs +- name: Inspect the merged settings (secrets masked) + ansible.builtin.debug: + msg: "{{ __pihole_effective | combine({'config': {'webserver': {'api': __pihole_masked_secrets}}}, recursive=True) }}" + vars: + __pihole_masked_secrets: {password: , app_password: , totp_secret: } + when: pihole_testing | bool + +- name: Pausing to highlight merge result + ansible.builtin.wait_for: + timeout: "{{ pihole_testing_timeout | default(5) }}" + when: pihole_testing | bool diff --git a/roles/pihole/tasks/reconfigure.yml b/roles/pihole/tasks/reconfigure.yml new file mode 100644 index 0000000..7cb5211 --- /dev/null +++ b/roles/pihole/tasks/reconfigure.yml @@ -0,0 +1,17 @@ +--- + +- name: Configure pihole.toml + become: true + ansible.builtin.template: + src: pihole.toml.j2 + # rather than hard-code /etc/pihole ourselves we can ride on the coat-tails + # of any of the __pihole_effective.config.files vars + dest: "{{ __pihole_effective.config.files.database | dirname }}/pihole.toml" + owner: "{{ __pihole_effective.user }}" + group: "{{ __pihole_effective.group }}" + mode: '0664' + when: not ansible_check_mode or __pihole_config_dir.stat.exists + notify: reconfigure pihole + # the rendered file holds the password hashes and the TOTP secret + no_log: true + diff: false diff --git a/roles/pihole/tasks/validate.yml b/roles/pihole/tasks/validate.yml new file mode 100644 index 0000000..b2b8664 --- /dev/null +++ b/roles/pihole/tasks/validate.yml @@ -0,0 +1,55 @@ +--- +# Input checks. Imported first in main.yml with tags: always, so a bad input fails before any +# change. pihole_web_password is required by the argument spec, which runs before this file. + +# The role also reads gathered facts (ansible_env.HOME, ansible_user_id), so a run without +# them fails here too. +- name: Require Ubuntu + ansible.builtin.assert: + that: + - ansible_facts['distribution'] | default('') == 'Ubuntu' + fail_msg: >- + pihole supports Ubuntu only (found: {{ ansible_facts['distribution'] | default('no gathered facts') }}). + The role reads gathered facts, so run it in a play that gathers them. + quiet: true + +# The merge is computed here as well as in merge-defaults.yml, so these checks run before +# anything else, on every tag selection. +- name: Check the merged Pi-hole settings + vars: + __pihole_candidate: "{{ pihole_default | combine(pihole_overrides | default({}), recursive=True) }}" + block: + - name: Check that at least one upstream DNS server is defined + ansible.builtin.assert: + that: + - __pihole_candidate.config.dns.upstreams is defined + - __pihole_candidate.config.dns.upstreams | length > 0 + fail_msg: pihole_overrides.config.dns.upstreams must be a non-empty list of upstream DNS servers. + quiet: true + + - name: Check that the DNS interface is set + ansible.builtin.assert: + that: + - __pihole_candidate.config.dns.interface is string + - __pihole_candidate.config.dns.interface | trim | length > 0 + fail_msg: >- + The merged config.dns.interface is empty. Set it through the pihole_overrides dictionary + (for example pihole_overrides.config.dns.interface: eth0); there is no role default. + quiet: true + + - name: Check that the web password is a string + ansible.builtin.assert: + that: + - __pihole_candidate.config.webserver.api.password is defined + - __pihole_candidate.config.webserver.api.password is string + fail_msg: The merged config.webserver.api.password must be a string. + quiet: true + + - name: Check that the web password has been changed from the placeholder + ansible.builtin.assert: + that: + - __pihole_candidate.config.webserver.api.password != "changetoyourownpassword" + fail_msg: >- + The web password is the placeholder changetoyourownpassword: set pihole_web_password, or + pihole_overrides.config.webserver.api.password, to a secret of your own. + quiet: true diff --git a/roles/pihole/templates/pihole.toml.j2 b/roles/pihole/templates/pihole.toml.j2 new file mode 100644 index 0000000..14c6be4 --- /dev/null +++ b/roles/pihole/templates/pihole.toml.j2 @@ -0,0 +1,1202 @@ +{# + SPDX-License-Identifier: GPL-3.0-only AND EUPL-1.2 + Derived from https://codeberg.org/ansible/pihole by Taha Ahmed (solarchemist), + upstream commit 95a20d4 (GPL-3.0), modified by Defame1297 (2026). The comment + text came in via that upstream from Pi-hole FTL v6.2.2/v6.2.3 + (src/config/config.c, https://github.com/pi-hole/FTL), Copyright Pi-hole, LLC, + EUPL-1.2. EUPL Art. 5 allows this combined work to be distributed under + GPL-3.0. See NOTICE. +#} +[dns] + # Array of upstream DNS servers used by Pi-hole + # Example: [ "8.8.8.8", "127.0.0.1#5335", "docker-resolver" ] + # + # Possible values are: + # array of IP addresses and/or hostnames, optionally with a port (#...) + {# https://stackoverflow.com/a/49255106 #} + {# the map("quote") approach works for upstreams but not for headers and possibly not other params #} + {# the "quote" filter apparently does not quote strings that contain spaces or whatever #} + {# upstreams = [ {{ __pihole_effective.config.dns.upstreams | map("quote") | join(", ") }} ] #} + upstreams = [ {{ '\"' + __pihole_effective.config.dns.upstreams | join('\", \"') + '\"' }} ] + + # Use this option to control deep CNAME inspection. Disabling it might be beneficial + # for very low-end devices + CNAMEdeepInspect = {{ __pihole_effective.config.dns.CNAMEdeepInspect }} + + # Should _esni. subdomains be blocked by default? Encrypted Server Name Indication + # (ESNI) is certainly a good step into the right direction to enhance privacy on the + # web. It prevents on-path observers, including ISPs, coffee shop owners and + # firewalls, from intercepting the TLS Server Name Indication (SNI) extension by + # encrypting it. This prevents the SNI from being used to determine which websites + # users are visiting. + # ESNI will obviously cause issues for pixelserv-tls which will be unable to generate + # matching certificates on-the-fly when it cannot read the SNI. Cloudflare and Firefox + # are already enabling ESNI. According to the IEFT draft (link above), we can easily + # restore piselserv-tls's operation by replying NXDOMAIN to _esni. subdomains of + # blocked domains as this mimics a "not configured for this domain" behavior. + blockESNI = {{ __pihole_effective.config.dns.blockESNI }} + + # Should we overwrite the query source when client information is provided through + # EDNS0 client subnet (ECS) information? This allows Pi-hole to obtain client IPs even + # if they are hidden behind the NAT of a router. This feature has been requested and + # discussed on Discourse where further information how to use it can be found: + # https://discourse.pi-hole.net/t/support-for-add-subnet-option-from-dnsmasq-ecs-edns0-client-subnet/35940 + EDNS0ECS = {{ __pihole_effective.config.dns.EDNS0ECS }} + + # Should FTL hide queries made by localhost? + ignoreLocalhost = {{ __pihole_effective.config.dns.ignoreLocalhost }} + + # Should FTL analyze and show internally generated DNSSEC queries? + showDNSSEC = {{ __pihole_effective.config.dns.showDNSSEC }} + + # Should FTL analyze *only* A and AAAA queries? + analyzeOnlyAandAAAA = {{ __pihole_effective.config.dns.analyzeOnlyAandAAAA }} + + # Controls whether and how FTL will reply with for address for which a local interface + # exists. Changing this setting causes FTL to restart. + # + # Possible values are: + # - "NONE" + # Pi-hole will not respond automatically on PTR requests to local interface + # addresses. Ensure pi.hole and/or hostname records exist elsewhere. + # - "HOSTNAME" + # Serve the machine's hostname. The hostname is queried from the kernel through + # uname(2)->nodename. If the machine has multiple network interfaces, it can + # also have multiple nodenames. In this case, it is unspecified and up to the + # kernel which one will be returned. On Linux, the returned string is what has + # been set using sethostname(2) which is typically what has been set in + # /etc/hostname. + # - "HOSTNAMEFQDN" + # Serve the machine's hostname (see limitations above) as fully qualified domain + # by adding the local domain. If no local domain has been defined (config option + # dns.domain), FTL tries to query the domain name from the kernel using + # getdomainname(2). If this fails, FTL appends ".no_fqdn_available" to the + # hostname. + # - "PI.HOLE" + # Respond with "pi.hole". + piholePTR = "{{ __pihole_effective.config.dns.piholePTR }}" + + # How should FTL handle queries when the gravity database is not available? + # + # Possible values are: + # - "BLOCK" + # Block all queries when the database is busy. + # - "ALLOW" + # Allow all queries when the database is busy. + # - "REFUSE" + # Refuse all queries which arrive while the database is busy. + # - "DROP" + # Just drop the queries, i.e., never reply to them at all. Despite "REFUSE" + # sounding similar to "DROP", it turned out that many clients will just + # immediately retry, causing up to several thousands of queries per second. This + # does not happen in "DROP" mode. + replyWhenBusy = "{{ __pihole_effective.config.dns.replyWhenBusy }}" + + # FTL's internal TTL to be handed out for blocked queries in seconds. This settings + # allows users to select a value different from the dnsmasq config option local-ttl. + # This is useful in context of locally used hostnames that are known to stay constant + # over long times (printers, etc.). + # Note that large values may render whitelisting ineffective due to client-side + # caching of blocked queries. + blockTTL = {{ __pihole_effective.config.dns.blockTTL }} + + # Array of custom DNS records + # Example: hosts = [ "127.0.0.1 mylocal", "192.168.0.1 therouter" ] + # + # Possible values are: + # Array of custom DNS records each one in HOSTS form: "IP HOSTNAME" + hosts = [ {{ '\"' + __pihole_effective.config.dns.hosts | join('\", \"') + '\"' }} ] + + # If set, A and AAAA queries for plain names, without dots or domain parts, are never + # forwarded to upstream nameservers + domainNeeded = {{ __pihole_effective.config.dns.domainNeeded }} + + # If set, the domain is added to simple names (without a period) in /etc/hosts in the + # same way as for DHCP-derived names + expandHosts = {{ __pihole_effective.config.dns.expandHosts }} + + # The DNS domain used by your Pi-hole. + # + # This DNS domain is purely local. FTL may answer queries from its local cache and + # configuration but *never* forwards any requests upstream *unless* you have + # configured a dns.revServer exactly for this domain. In the latter case, all queries + # for this domain are sent exclusively to this server (including reverse lookups). + # + # For DHCP, this has two effects; firstly it causes the DHCP server to return the + # domain to any hosts which request it, and secondly it sets the domain which it is + # legal for DHCP-configured hosts to claim. The intention is to constrain hostnames so + # that an untrusted host on the LAN cannot advertise its name via DHCP as e.g. + # "google.com" and capture traffic not meant for it. If no domain suffix is specified, + # then any DHCP hostname with a domain part (ie with a period) will be disallowed and + # logged. If a domain is specified, then hostnames with a domain part are allowed, + # provided the domain part matches the suffix. In addition, when a suffix is set then + # hostnames without a domain part have the suffix added as an optional domain part. + # For instance, we can set domain=mylab.com and have a machine whose DHCP hostname is + # "laptop". The IP address for that machine is available both as "laptop" and + # "laptop.mylab.com". + # + # You can disable setting a domain by setting this option to an empty string. + # + # Possible values are: + # + domain = "{{ __pihole_effective.config.dns.domain }}" + + # Should all reverse lookups for private IP ranges (i.e., 192.168.x.y, etc) which are + # not found in /etc/hosts or the DHCP leases file be answered with "no such domain" + # rather than being forwarded upstream? + bogusPriv = {{ __pihole_effective.config.dns.bogusPriv }} + + # Validate DNS replies using DNSSEC? + dnssec = {{ __pihole_effective.config.dns.dnssec }} + + # Interface to use for DNS (see also dnsmasq.listening.mode) and DHCP (if enabled) + # + # Possible values are: + # a valid interface name + interface = "{{ __pihole_effective.config.dns.interface }}" + + # Add A, AAAA and PTR records to the DNS. This adds one or more names to the DNS with + # associated IPv4 (A) and IPv6 (AAAA) records + # + # Possible values are: + # [,....],[],[][,] + hostRecord = "{{ __pihole_effective.config.dns.hostRecord }}" + + # Pi-hole interface listening modes + # + # Possible values are: + # - "LOCAL" + # Allow only local requests. This setting accepts DNS queries only from hosts + # whose address is on a local subnet, i.e., a subnet for which an interface + # exists on the server. It is intended to be set as a default on installation, + # to allow unconfigured installations to be useful but also safe from being used + # for DNS amplification attacks if (accidentally) running public. + # - "SINGLE" + # Permit all origins, accept only on the specified interface. Respond only to + # queries arriving on the specified interface. The loopback (lo) interface is + # automatically added to the list of interfaces to use when this option is used. + # Make sure your Pi-hole is properly firewalled! + # - "BIND" + # By default, FTL binds the wildcard address. If this is not what you want, you + # can use this option as it forces FTL to really bind only the interfaces it is + # listening on. Note that this may result in issues when the interface may go + # down (cable unplugged, etc.). About the only time when this is useful is when + # running another nameserver on the same port on the same machine. This may also + # happen if you run a virtualization API such as libvirt. When this option is + # used, IP alias interface labels (e.g. enp2s0:0) are checked rather than + # interface names. + # - "ALL" + # Permit all origins, accept on all interfaces. Make sure your Pi-hole is + # properly firewalled! This truly allows any traffic to be replied to and is a + # dangerous thing to do as your Pi-hole could become an open resolver. You + # should always ask yourself if the first option doesn't work for you as well. + # - "NONE" + # Do not add any configuration concerning the listening mode to the dnsmasq + # configuration file. This is useful if you want to manually configure the + # listening mode in auxiliary configuration files. This option is really meant + # for advanced users only, support for this option may be limited. + listeningMode = "{{ __pihole_effective.config.dns.listeningMode }}" + + # Log DNS queries and replies to pihole.log + queryLogging = {{ __pihole_effective.config.dns.queryLogging }} + + # List of CNAME records which indicate that is really . If the is + # given, it overwrites the value of local-ttl + # + # Possible values are: + # Array of CNAMEs each on in one of the following forms: ",[,]" + cnameRecords = [ {{ '\"' + __pihole_effective.config.dns.cnameRecords | join('\", \"') + '\"' }} ] + + # Port used by the DNS server + port = {{ __pihole_effective.config.dns.port }} + + # Reverse server (former also called "conditional forwarding") feature + # Array of reverse servers each one in one of the following forms: + # ",[/],[#][,]" + # + # Individual components: + # + # : either "true" or "false" + # + # [/]: Address range for the reverse server feature in CIDR + # notation. If the prefix length is omitted, either 32 (IPv4) or 128 (IPv6) are + # substituted (exact address match). This is almost certainly not what you want here. + # Example: "192.168.0.0/24" for the range 192.168.0.1 - 192.168.0.255 + # + # [#]: Target server to be used for the reverse server feature + # Example: "192.168.0.1#53" + # + # : Domain used for the reverse server feature (e.g., "fritz.box") + # Example: "fritz.box" + # + # Possible values are: + # array of reverse servers each one in one of the following forms: + # ",[/],[#][,]", e.g., + # "true,192.168.0.0/24,192.168.0.1,fritz.box" + revServers = [ {{ '\"' + __pihole_effective.config.dns.revServers | join('\", \"') + '\"' }} ] + + [dns.cache] + # Cache size of the DNS server. Note that expiring cache entries naturally make room + # for new insertions over time. Setting this number too high will have an adverse + # effect as not only more space is needed, but also lookup speed gets degraded in the + # 10,000+ range. dnsmasq may issue a warning when you go beyond 10,000+ cache entries. + size = {{ __pihole_effective.config.dns.cache.size }} + + # Query cache optimizer: If a DNS name exists in the cache, but its time-to-live has + # expired only recently, the data will be used anyway (a refreshing from upstream is + # triggered). This can improve DNS query delays especially over unreliable Internet + # connections. This feature comes at the expense of possibly sometimes returning + # out-of-date data and less efficient cache utilization, since old data cannot be + # flushed when its TTL expires, so the cache becomes mostly least-recently-used. To + # mitigate issues caused by massively outdated DNS replies, the maximum overaging of + # cached records is limited. We strongly recommend staying below 86400 (1 day) with + # this option. + # Setting the TTL excess time to zero will serve stale cache data regardless how long + # it has expired. This is not recommended as it may lead to stale data being served + # for a long time. Setting this option to any negative value will disable this feature + # altogether. + optimizer = {{ __pihole_effective.config.dns.cache.optimizer }} + + # This setting allows you to specify the TTL used for queries blocked upstream. Once + # the TTL expires, the query will be forwarded to the upstream server again to check + # if the block is still valid. Defaults to caching for one day (86400 seconds). + # Setting this value to zero disables caching of queries blocked upstream. + upstreamBlockedTTL = {{ __pihole_effective.config.dns.cache.upstreamBlockedTTL }} + + [dns.blocking] + # Should FTL block queries? + active = {{ __pihole_effective.config.dns.blocking.active }} + + # How should FTL reply to blocked queries? + # + # Possible values are: + # - "NULL" + # In NULL mode, which is both the default and recommended mode for Pi-hole + # FTLDNS, blocked queries will be answered with the "unspecified address" + # (0.0.0.0 or ::). The "unspecified address" is a reserved IP address specified + # by RFC 3513 - Internet Protocol Version 6 (IPv6) Addressing Architecture, + # section 2.5.2. + # - "IP_NODATA_AAAA" + # In IP-NODATA-AAAA mode, blocked queries will be answered with the local IPv4 + # addresses of your Pi-hole. Blocked AAAA queries will be answered with + # NODATA-IPV6 and clients will only try to reach your Pi-hole over its static + # IPv4 address. + # - "IP" + # In IP mode, blocked queries will be answered with the local IP addresses of + # your Pi-hole. + # - "NX" + # In NXDOMAIN mode, blocked queries will be answered with an empty response + # (i.e., there won't be an answer section) and status NXDOMAIN. A NXDOMAIN + # response should indicate that there is no such domain to the client making the + # query. + # - "NODATA" + # In NODATA mode, blocked queries will be answered with an empty response (no + # answer section) and status NODATA. A NODATA response indicates that the domain + # exists, but there is no record for the requested query type. + mode = "{{ __pihole_effective.config.dns.blocking.mode }}" + + # Should FTL enrich blocked replies with EDNS0 information? + # + # Possible values are: + # - "NONE" + # In NONE mode, no additional EDNS information is added to blocked queries + # - "CODE" + # In CODE mode, blocked queries will be enriched with EDNS info-code BLOCKED (15) + # - "TEXT" + # In TEXT mode, blocked queries will be enriched with EDNS info-code BLOCKED (15) + # and a text message describing the reason for the block + edns = "{{ __pihole_effective.config.dns.blocking.edns }}" + + [dns.specialDomains] + # Should Pi-hole always reply with NXDOMAIN to A and AAAA queries of + # use-application-dns.net to disable Firefox automatic DNS-over-HTTP? This is + # following the recommendation on + # https://support.mozilla.org/en-US/kb/configuring-networks-disable-dns-over-https + mozillaCanary = {{ __pihole_effective.config.dns.specialDomains.mozillaCanary }} + + # Should Pi-hole always reply with NXDOMAIN to A and AAAA queries of mask.icloud.com + # and mask-h2.icloud.com to disable Apple's iCloud Private Relay to prevent Apple + # devices from bypassing Pi-hole? This is following the recommendation on + # https://developer.apple.com/support/prepare-your-network-for-icloud-private-relay + iCloudPrivateRelay = {{ __pihole_effective.config.dns.specialDomains.iCloudPrivateRelay }} + + # Should Pi-hole always reply with NODATA to all queries to zone resolver.arpa to + # prevent devices from bypassing Pi-hole using Discovery of Designated Resolvers? This + # is based on recommendations at the end of RFC 9462, section 4. + designatedResolver = {{ __pihole_effective.config.dns.specialDomains.designatedResolver }} + + [dns.reply.host] + # Use a specific IPv4 address for the Pi-hole host? By default, FTL determines the + # address of the interface a query arrived on and uses this address for replying to A + # queries with the most suitable address for the requesting client. This setting can + # be used to use a fixed, rather than the dynamically obtained, address when Pi-hole + # responds to the following names: [ "pi.hole", "", + # "pi.hole.", "." ] + force4 = {{ __pihole_effective.config.dns.reply.host.force4 }} + + # Custom IPv4 address for the Pi-hole host + # + # Possible values are: + # or empty string ("") + IPv4 = "{{ __pihole_effective.config.dns.reply.host.IPv4 }}" + + # Use a specific IPv6 address for the Pi-hole host? See description for the IPv4 + # variant above for further details. + force6 = {{ __pihole_effective.config.dns.reply.host.force6 }} + + # Custom IPv6 address for the Pi-hole host + # + # Possible values are: + # or empty string ("") + IPv6 = "{{ __pihole_effective.config.dns.reply.host.IPv6 }}" + + [dns.reply.blocking] + # Use a specific IPv4 address in IP blocking mode? By default, FTL determines the + # address of the interface a query arrived on and uses this address for replying to A + # queries with the most suitable address for the requesting client. This setting can + # be used to use a fixed, rather than the dynamically obtained, address when Pi-hole + # responds in the following cases: IP blocking mode is used and this query is to be + # blocked, regular expressions with the ;reply=IP regex extension. + force4 = {{ __pihole_effective.config.dns.reply.blocking.force4 }} + + # Custom IPv4 address for IP blocking mode + # + # Possible values are: + # or empty string ("") + IPv4 = "{{ __pihole_effective.config.dns.reply.blocking.IPv4 }}" + + # Use a specific IPv6 address in IP blocking mode? See description for the IPv4 variant + # above for further details. + force6 = {{ __pihole_effective.config.dns.reply.blocking.force6 }} + + # Custom IPv6 address for IP blocking mode + # + # Possible values are: + # or empty string ("") + IPv6 = "{{ __pihole_effective.config.dns.reply.blocking.IPv6 }}" + + [dns.rateLimit] + # Rate-limited queries are answered with a REFUSED reply and not further processed by + # FTL. + # The default settings for FTL's rate-limiting are to permit no more than 1000 queries + # in 60 seconds. Both numbers can be customized independently. It is important to note + # that rate-limiting is happening on a per-client basis. Other clients can continue to + # use FTL while rate-limited clients are short-circuited at the same time. + # For this setting, both numbers, the maximum number of queries within a given time, + # and the length of the time interval (seconds) have to be specified. For instance, if + # you want to set a rate limit of 1 query per hour, the option should look like + # dns.rateLimit.count=1 and dns.rateLimit.interval=3600. The time interval is relative + # to when FTL has finished starting (start of the daemon + possible delay by + # DELAY_STARTUP) then it will advance in steps of the rate-limiting interval. If a + # client reaches the maximum number of queries it will be blocked until the end of the + # current interval. This will be logged to /var/log/pihole/FTL.log, e.g. Rate-limiting + # 10.0.1.39 for at least 44 seconds. If the client continues to send queries while + # being blocked already and this number of queries during the blocking exceeds the + # limit the client will continue to be blocked until the end of the next interval + # (FTL.log will contain lines like Still rate-limiting 10.0.1.39 as it made additional + # 5007 queries). As soon as the client requests less than the set limit, it will be + # unblocked (Ending rate-limitation of 10.0.1.39). + # Rate-limiting may be disabled altogether by setting both values to zero (this + # results in the same behavior as before FTL v5.7). + # How many queries are permitted... + count = {{ __pihole_effective.config.dns.rateLimit.count }} + + # ... in the set interval before rate-limiting? + interval = {{ __pihole_effective.config.dns.rateLimit.interval }} + +[dhcp] + # Is the embedded DHCP server enabled? + active = {{ __pihole_effective.config.dhcp.active }} + + # Start address of the DHCP address pool + # + # Possible values are: + # or empty string (""), e.g., "192.168.0.10" + start = "{{ __pihole_effective.config.dhcp.start }}" + + # End address of the DHCP address pool + # + # Possible values are: + # or empty string (""), e.g., "192.168.0.250" + end = "{{ __pihole_effective.config.dhcp.end }}" + + # Address of the gateway to be used (typically the address of your router in a home + # installation) + # + # Possible values are: + # or empty string (""), e.g., "192.168.0.1" + router = "{{ __pihole_effective.config.dhcp.router }}" + + # The netmask used by your Pi-hole. For directly connected networks (i.e., networks on + # which the machine running Pi-hole has an interface) the netmask is optional and may + # be set to an empty string (""): it will then be determined from the interface + # configuration itself. For networks which receive DHCP service via a relay agent, we + # cannot determine the netmask itself, so it should explicitly be specified, otherwise + # Pi-hole guesses based on the class (A, B or C) of the network address. + # + # Possible values are: + # (e.g., "255.255.255.0") or empty string ("") for + # auto-discovery + netmask = "{{ __pihole_effective.config.dhcp.netmask }}" + + # If the lease time is given, then leases will be given for that length of time. If not + # given, the default lease time is one hour for IPv4 and one day for IPv6. + # + # Possible values are: + # The lease time can be in seconds, or minutes (e.g., "45m") or hours (e.g., "1h") + # or days (like "2d") or even weeks ("1w"). You may also use "infinite" as string + # but be aware of the drawbacks + leaseTime = "{{ __pihole_effective.config.dhcp.leaseTime }}" + + # Should Pi-hole make an attempt to also satisfy IPv6 address requests (be aware that + # IPv6 works a whole lot different than IPv4) + ipv6 = {{ __pihole_effective.config.dhcp.ipv6 }} + + # Enable DHCPv4 Rapid Commit Option specified in RFC 4039. Should only be enabled if + # either the server is the only server for the subnet to avoid conflicts + rapidCommit = {{ __pihole_effective.config.dhcp.rapidCommit }} + + # Advertise DNS server multiple times to clients. Some devices will add their own + # proprietary DNS servers to the list of DNS servers, which can cause issues with + # Pi-hole. This option will advertise the Pi-hole DNS server multiple times to + # clients, which should prevent this from happening. + multiDNS = {{ __pihole_effective.config.dhcp.multiDNS }} + + # Enable logging for DHCP. This will log all relevant DHCP-related activity, including, + # e.g., all the options sent to DHCP clients and the tags used to determine them (if + # any). This can be useful for debugging DHCP issues. The generated output is saved to + # the file specified by files.log.dnsmasq below. + logging = {{ __pihole_effective.config.dhcp.logging }} + + # Ignore unknown DHCP clients. + # If this option is set, Pi-hole ignores all clients which are not explicitly + # configured through dhcp.hosts. This can be useful to prevent unauthorized clients + # from getting an IP address from the DHCP server. + # It should be noted that this option is not a security feature, as clients can still + # assign themselves an IP address and use the network. It is merely a convenience + # feature to prevent unknown clients from getting a valid IP configuration assigned + # automatically. + # Note that you will need to configure new clients manually in dhcp.hosts before they + # can use the network when this feature is enabled. + ignoreUnknownClients = {{ __pihole_effective.config.dhcp.ignoreUnknownClients }} + + # Per host parameters for the DHCP server. This allows a machine with a particular + # hardware address to be always allocated the same hostname, IP address and lease time + # or to specify static DHCP leases + # + # Possible values are: + # Array of static leases each on in one of the following forms: + # "[][,id:|*][,set:][,tag:][,][,][,][,ignore]" + hosts = [ {{ '\"' + __pihole_effective.config.dhcp.hosts | join('\", \"') + '\"' }} ] + + [ntp.ipv4] + # Should FTL act as network time protocol (NTP) server (IPv4)? + active = {{ __pihole_effective.config.ntp.ipv4.active }} + + # IPv4 address to listen on for NTP requests + # + # Possible values are: + # or empty string ("") for wildcard (0.0.0.0) + address = "{{ __pihole_effective.config.ntp.ipv4.address }}" + + [ntp.ipv6] + # Should FTL act as network time protocol (NTP) server (IPv6)? + active = {{ __pihole_effective.config.ntp.ipv6.active }} + + # IPv6 address to listen on for NTP requests + # + # Possible values are: + # or empty string ("") for wildcard (::) + address = "{{ __pihole_effective.config.ntp.ipv6.address }}" + + [ntp.sync] + # Should FTL try to synchronize the system time with an upstream NTP server? + active = {{ __pihole_effective.config.ntp.sync.active }} + + # NTP upstream server to sync with, e.g., "pool.ntp.org". Note that the NTP server + # should be located as close as possible to you in order to minimize the time offset + # possibly introduced by different routing paths. + # + # Possible values are: + # valid NTP upstream server + server = "{{ __pihole_effective.config.ntp.sync.server }}" + + # Interval in seconds between successive synchronization attempts with the NTP server + interval = {{ __pihole_effective.config.ntp.sync.interval }} + + # Number of NTP syncs to perform and average before updating the system time + count = {{ __pihole_effective.config.ntp.sync.count }} + + [ntp.sync.rtc] + # Should FTL update a real-time clock (RTC) if available? + set = {{ __pihole_effective.config.ntp.sync.rtc.set }} + + # Path to the RTC device to update. Leave empty for auto-discovery + # + # Possible values are: + # Path to the RTC device, e.g., "/dev/rtc0" + device = "{{ __pihole_effective.config.ntp.sync.rtc.device }}" + + # Should the RTC be set to UTC? + utc = {{ __pihole_effective.config.ntp.sync.rtc.utc }} + +[resolver] + # Should FTL try to resolve IPv4 addresses to hostnames? + resolveIPv4 = {{ __pihole_effective.config.resolver.resolveIPv4 }} + + # Should FTL try to resolve IPv6 addresses to hostnames? + resolveIPv6 = {{ __pihole_effective.config.resolver.resolveIPv6 }} + + # Control whether FTL should use the fallback option to try to obtain client names from + # checking the network table. This behavior can be disabled with this option. + # Assume an IPv6 client without a host names. However, the network table knows - + # though the client's MAC address - that this is the same device where we have a host + # name for another IP address (e.g., a DHCP server managed IPv4 address). In this + # case, we use the host name associated to the other address as this is the same + # device. + networkNames = {{ __pihole_effective.config.resolver.networkNames }} + + # With this option, you can change how (and if) hourly PTR requests are made to check + # for changes in client and upstream server hostnames. + # + # Possible values are: + # - "IPV4_ONLY" + # Do hourly PTR lookups only for IPv4 addresses. This is the new default since + # Pi-hole FTL v5.3.2. It should resolve issues with more and more very + # short-lived PE IPv6 addresses coming up in a lot of networks. + # - "ALL" + # Do hourly PTR lookups for all addresses. This was the default until FTL + # v5.3(.1). It has been replaced as it can create a lot of PTR queries for those + # with many IPv6 addresses in their networks. + # - "UNKNOWN" + # Only resolve unknown hostnames. Already existing hostnames are never refreshed, + # i.e., there will be no PTR queries made for clients where hostnames are known. + # This also means that known hostnames will not be updated once known. + # - "NONE" + # Don't do any hourly PTR lookups. This means we look host names up exactly once + # (when we first see a client) and never again. You may miss future changes of + # host names. + refreshNames = "{{ __pihole_effective.config.resolver.refreshNames }}" + +[database] + # Should FTL load information from the database on startup to be aware of the most + # recent history? + DBimport = {{ __pihole_effective.config.database.DBimport }} + + # How long should queries be stored in the database [days]? + # Setting this value to 0 will disable the database. + maxDBdays = {{ __pihole_effective.config.database.maxDBdays }} + + # How often do we store queries in FTL's database [seconds]? + DBinterval = {{ __pihole_effective.config.database.DBinterval }} + + # Should FTL enable Write-Ahead Log (WAL) mode for the on-disk query database + # (configured via files.database)? + # It is recommended to leave this setting enabled for performance reasons. About the + # only reason to disable WAL mode is if you are experiencing specific issues with it, + # e.g., when using a database that is accessed from multiple hosts via a network + # share. When this setting is disabled, FTL will use SQLite3's default journal mode + # (rollback journal in DELETE mode). + useWAL = {{ __pihole_effective.config.database.useWAL }} + + [database.network] + # Should FTL analyze the local ARP cache? When disabled, client identification and the + # network table will stop working reliably. + parseARPcache = {{ __pihole_effective.config.database.network.parseARPcache }} + + # How long should IP addresses be kept in the network_addresses table [days]? IP + # addresses (and associated host names) older than the specified number of days are + # removed to avoid dead entries in the network overview table. + expire = {{ __pihole_effective.config.database.network.expire }} + +[webserver] + # On which domain is the web interface served? + # + # Possible values are: + # + domain = "{{ __pihole_effective.config.webserver.domain }}" + + # Webserver access control list (ACL) allowing for restrictions to be put on the list + # of IP addresses which have access to the web server. The ACL is a comma separated + # list of IP subnets, where each subnet is prepended by either a - or a + sign. A plus + # sign means allow, where a minus sign means deny. If a subnet mask is omitted, such + # as -1.2.3.4, this means to deny only that single IP address. If this value is not + # set (empty string), all accesses are allowed. Otherwise, the default setting is to + # deny all accesses. On each request the full list is traversed, and the last (!) + # match wins. IPv6 addresses may be specified in CIDR-form [a:b::c]/64. + # + # Example 1: acl = "+127.0.0.1,+[::1]" + # ---> deny all access, except from 127.0.0.1 and ::1, + # Example 2: acl = "+192.168.0.0/16" + # ---> deny all accesses, except from the 192.168.0.0/16 subnet, + # Example 3: acl = "+[::]/0" ---> allow only IPv6 access. + # + # Possible values are: + # + acl = "{{ __pihole_effective.config.webserver.acl }}" + + # Ports to be used by the webserver. + # Comma-separated list of ports to listen on. It is possible to specify an IP address + # to bind to. In this case, an IP address and a colon must be prepended to the port + # number. For example, to bind to the loopback interface on port 80 (IPv4) and to all + # interfaces port 8080 (IPv4), use "127.0.0.1:80,8080". "[::]:80" can be used to + # listen to IPv6 connections to port 80. IPv6 addresses of network interfaces can be + # specified as well, e.g. "[::1]:80" for the IPv6 loopback interface. [::]:80 will + # bind to port 80 IPv6 only. + # In order to use port 80 for all interfaces, both IPv4 and IPv6, use either the + # configuration "80,[::]:80" (create one socket for IPv4 and one for IPv6 only), or + # "+80" (create one socket for both, IPv4 and IPv6). The '+' notation to use IPv4 and + # IPv6 will only work if no network interface is specified. Depending on your + # operating system version and IPv6 network environment, some configurations might not + # work as expected, so you have to test to find the configuration most suitable for + # your needs. In case "+80" does not work for your environment, you need to use + # "80,[::]:80". + # If the port is TLS/SSL, a letter 's' (secure) must be appended, for example, + # "80,443s" will open port 80 and port 443, and connections on port 443 will be + # encrypted. For non-encrypted ports, it is allowed to append letter 'r' (as in + # redirect). Redirected ports will redirect all their traffic to the first configured + # SSL port. For example, if webserver.port is "80r,443s", then all HTTP traffic coming + # at port 80 will be redirected to HTTPS port 443. + # When specifying 'o' (optional) behind a port, inability to use this port is not + # considered an error. For instance, specifying "80o,8080o" will allow the webserver + # to listen on either 80, 8080, both or even none of the two ports. This flag may be + # combined with 'r' and 's' like "80or,443os,8080,4443s" (80 redirecting to SSL if + # available, 443 encrypted if available, 8080 mandatory and unencrypted, 4443 + # mandatory and encrypted). + # If this value is not set (empty string), the web server will not be started and, + # hence, the API will not be available. + # + # Possible values are: + # comma-separated list of <[ip_address:]port> + port = "{{ __pihole_effective.config.webserver.port }}" + + # Maximum number of worker threads allowed. + # The Pi-hole web server handles each incoming connection in a separate thread. + # Therefore, the value of this option is effectively the number of concurrent HTTP + # connections that can be handled. Any other connections are queued until they can be + # processed by a unoccupied thread. + # The total number of threads you see may be lower than the configured value as + # threads are only created when needed due to incoming connections. + # The value 0 means the number of threads is 50 (as per default settings of CivetWeb) + # for backwards-compatible behavior. + threads = {{ __pihole_effective.config.webserver.threads }} + + # Additional HTTP headers added to the web server responses. + # The headers are added to all responses, including those for the API. + # Note about the default additional headers: + # - X-DNS-Prefetch-Control: off: Usually browsers proactively perform domain name + # resolution on links that the user may choose to follow. We disable DNS prefetching + # here. + # - Content-Security-Policy: [...] 'unsafe-inline' is both required by Chart.js + # styling some elements directly, and index.html containing some inlined Javascript + # code. + # - X-Frame-Options: DENY: The page can not be displayed in a frame, regardless of the + # site attempting to do so. + # - X-Xss-Protection: 0: Disables XSS filtering in browsers that support it. This + # header is usually enabled by default in browsers, and is not recommended as it can + # hurt the security of the site. + # (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection). + # - X-Content-Type-Options: nosniff: Marker used by the server to indicate that the + # MIME types advertised in the Content-Type headers should not be changed and be + # followed. This allows to opt-out of MIME type sniffing, or, in other words, it is a + # way to say that the webmasters knew what they were doing. Site security testers + # usually expect this header to be set. + # - Referrer-Policy: strict-origin-when-cross-origin: A referrer will be sent for + # same-site origins, but cross-origin requests will send no referrer information. + # The latter four headers are set as expected by https://securityheaders.io + # + # Possible values are: + # array of HTTP headers + headers = [ {{ '\"' + __pihole_effective.config.webserver.headers | join('\", \"') + '\"' }} ] + + # Should the web server serve all files in webserver.paths.webroot directory? If + # disabled, only files within the path defined through webserver.paths.webhome and + # /api will be served. + serve_all = {{ __pihole_effective.config.webserver.serve_all }} + + [webserver.session] + # Session timeout in seconds. If a session is inactive for more than this time, it will + # be terminated. Sessions are continuously refreshed by the web interface, preventing + # sessions from timing out while the web interface is open. + # This option may also be used to make logins persistent for long times, e.g. 86400 + # seconds (24 hours), 604800 seconds (7 days) or 2592000 seconds (30 days). Note that + # the total number of concurrent sessions is limited so setting this value too high + # may result in users being rejected and unable to log in if there are already too + # many sessions active. + timeout = {{ __pihole_effective.config.webserver.session.timeout }} + + # Should Pi-hole backup and restore sessions from the database? This is useful if you + # want to keep your sessions after a restart of the web interface. + restore = {{ __pihole_effective.config.webserver.session.restore }} + + [webserver.tls] + # Path to the TLS (SSL) certificate file. All directories along the path must be + # readable and accessible by the user running FTL (typically 'pihole'). This option is + # only required when at least one of webserver.port is TLS. The file must be in PEM + # format, and it must have both, private key and certificate (the *.pem file created + # must contain a 'CERTIFICATE' section as well as a 'RSA PRIVATE KEY' section). + # The *.pem file can be created using + # cp server.crt server.pem + # cat server.key >> server.pem + # if you have these files instead + # + # Possible values are: + # + cert = "{{ __pihole_effective.config.webserver.tls.cert }}" + + [webserver.paths] + # Server root on the host + # + # Possible values are: + # + webroot = "{{ __pihole_effective.config.webserver.paths.webroot }}" + + # Sub-directory of the root containing the web interface + # + # Possible values are: + # , both slashes are needed! + webhome = "{{ __pihole_effective.config.webserver.paths.webhome }}" + + # Prefix where the web interface is served + # This is useful when you are using a reverse proxy serving the web interface, e.g., + # at http:///pihole/admin/ instead of http:///admin/. In this example, the + # prefix would be "/pihole". Note that the prefix has to be stripped away by the + # reverse proxy, e.g., for traefik: + # - traefik.http.routers.pihole.rule=PathPrefix(`/pihole`) + # - traefik.http.middlewares.piholehttp.stripprefix.prefixes=/pihole + # The prefix should start with a slash. If you don't use a prefix, leave this field + # empty. Setting this field to an incorrect value may result in the web interface not + # being accessible. + # Don't use this setting if you are not using a reverse proxy! + # + # Possible values are: + # valid URL prefix or empty + prefix = "{{ __pihole_effective.config.webserver.paths.prefix }}" + + [webserver.interface] + # Should the web interface use the boxed layout? + boxed = {{ __pihole_effective.config.webserver.interface.boxed }} + + # Theme used by the Pi-hole web interface + # + # Possible values are: + # - "default-auto" + # Pi-hole auto + # - "default-light" + # Pi-hole day + # - "default-dark" + # Pi-hole midnight + # - "default-darker" + # Pi-hole deep-midnight + # - "high-contrast" + # High-contrast light + # - "high-contrast-dark" + # High-contrast dark + # - "lcars" + # Star Trek LCARS + theme = "{{ __pihole_effective.config.webserver.interface.theme }}" + + [webserver.api] + # Number of concurrent sessions allowed for the API. If the number of sessions exceeds + # this value, no new sessions will be allowed until the number of sessions drops due + # to session expiration or logout. Note that the number of concurrent sessions is + # irrelevant if authentication is disabled as no sessions are used in this case. + max_sessions = {{ __pihole_effective.config.webserver.api.max_sessions }} + + # Should FTL prettify the API output (add extra spaces, newlines and indentation)? + prettyJSON = "{{ __pihole_effective.config.webserver.api.prettyJSON }}" + + # API password hash + # + # Possible values are: + # + # pwhash = "$BALLOON-SHA256$v=1$s=1024,t=32$U3jXb7H12Wl3tI/DpdVL6g==$8buijid3QdWNWHBalRuiIHBwxWUUvExsM598oAsbqkI=" ### CHANGED, default = "" + # Double-hashing (just like we did in Pi-Hole v5) still works. + # But if you want other approaches, consider: + # $ pihole-FTL --config webserver.api.password "RANDOMPASSWORD" >/dev/null + # or perhaps the `pihole setpassword "RANDOMPASSWORD"` command + # https://github.com/pi-hole/docker-pi-hole/blob/f4aac365653ffe7d8dbe9472193026e78cdfd174/src/bash_functions.sh#L212 + pwhash = "{{ __pihole_effective.config.webserver.api.password | hash('sha256') | hash('sha256') }}" + + # Pi-hole 2FA TOTP secret. When set to something different than "", 2FA authentication + # will be enforced for the API and the web interface. This setting is write-only, you + # can not read the secret back. + # + # Possible values are: + # + totp_secret = "{{ __pihole_effective.config.webserver.api.totp_secret }}" + + # Pi-hole application password. + # After you turn on two-factor (2FA) verification and set up an Authenticator app, you + # may run into issues if you use apps or other services that don't support two-step + # verification. In this case, you can create and use an app password to sign in. An + # app password is a long, randomly generated password that can be used instead of your + # regular password + TOTP token when signing in to the API. The app password can be + # generated through the API and will be shown only once. You can revoke the app + # password at any time. If you revoke the app password, be sure to generate a new one + # and update your app with the new password. + # + # Possible values are: + # + # NOTE! I am assuming this should be double-hashed just like the regular password, but + # this assumption has not been tested! + app_pwhash = "{{ __pihole_effective.config.webserver.api.app_password | hash('sha256') | hash('sha256') }}" + + # Should application password API sessions be allowed to modify config settings? + # Setting this to true allows third-party applications using the application password + # to modify settings, e.g., the upstream DNS servers, DHCP server settings, or + # changing passwords. This setting should only be enabled if really needed and only if + # you trust the applications using the application password. + app_sudo = {{ __pihole_effective.config.webserver.api.app_sudo }} + + # Should FTL create a temporary CLI password? This password is stored in clear in + # /etc/pihole and can be used by the CLI (pihole ... commands) to authenticate + # against the API. Note that the password is only valid for the current session and + # regenerated on each FTL restart. Sessions initiated with this password cannot modify + # the Pi-hole configuration (change passwords, etc.) for security reasons but can + # still use the API to query data and manage lists. + cli_pw = {{ __pihole_effective.config.webserver.api.cli_pw }} + + # Array of clients to be excluded from certain API responses (regex): + # - Query Log (/api/queries) + # - Top Clients (/api/stats/top_clients) + # This setting accepts both IP addresses (IPv4 and IPv6) as well as hostnames. + # Note that backslashes "\" need to be escaped, i.e. "\\" in this setting + # + # Example: [ "^192\\.168\\.2\\.56$", "^fe80::341:[0-9a-f]*$", "^localhost$" ] + # + # Possible values are: + # array of regular expressions describing clients + excludeClients = [ {{ '\"' + __pihole_effective.config.webserver.api.excludeClients | join('\", \"') + '\"' }} ] + + # Array of domains to be excluded from certain API responses (regex): + # - Query Log (/api/queries) + # - Top Clients (/api/stats/top_domains) + # Note that backslashes "\" need to be escaped, i.e. "\\" in this setting + # + # Example: [ "(^|\\.)\\.google\\.de$", "\\.pi-hole\\.net$" ] + # + # Possible values are: + # array of regular expressions describing domains + excludeDomains = [ {{ '\"' + __pihole_effective.config.webserver.api.excludeDomains | join('\", \"') + '\"' }} ] + + # How much history should be imported from the database and returned by the API + # [seconds]? (max 24*60*60 = 86400) + maxHistory = {{ __pihole_effective.config.webserver.api.maxHistory }} + + # Up to how many clients should be returned in the activity graph endpoint + # (/api/history/clients)? + # This setting can be overwritten at run-time using the parameter N. Setting this to 0 + # will always send all clients. Be aware that this may be challenging for the GUI if + # you have many (think > 1.000 clients) in your network + maxClients = {{ __pihole_effective.config.webserver.api.maxClients }} + + # How should the API compute the most active clients? If set to true, the API will + # return the clients with the most queries globally (within 24 hours). If set to + # false, the API will return the clients with the most queries per time slot + # individually. + client_history_global_max = {{ __pihole_effective.config.webserver.api.client_history_global_max }} + + # Allow destructive API calls (e.g. restart DNS server, flush logs, ...) + allow_destructive = {{ __pihole_effective.config.webserver.api.allow_destructive }} + + [webserver.api.temp] + # Which upper temperature limit should be used by Pi-hole? Temperatures above this + # limit will be shown as "hot". The number specified here is in the unit defined below + limit = {{ __pihole_effective.config.webserver.api.temp.limit }} + + # Which temperature unit should be used for temperatures processed by FTL? + # + # Possible values are: + # - "C" + # Celsius + # - "F" + # Fahrenheit + # - "K" + # Kelvin + unit = "{{ __pihole_effective.config.webserver.api.temp.unit }}" + +[files] + # The file which contains the PID of FTL's main process. + # + # Possible values are: + # + pid = "{{ __pihole_effective.config.files.pid }}" + + # The location of FTL's long-term database + # + # Possible values are: + # + database = "{{ __pihole_effective.config.files.database }}" + + # The location of Pi-hole's gravity database + # + # Possible values are: + # + gravity = "{{ __pihole_effective.config.files.gravity }}" + + # A temporary directory where Pi-hole can store files during gravity updates. This + # directory must be writable by the user running gravity (typically pihole). + # + # Possible values are: + # + gravity_tmp = "{{ __pihole_effective.config.files.gravity_tmp }}" + + # The database containing MAC -> Vendor information for the network table + # + # Possible values are: + # + macvendor = "{{ __pihole_effective.config.files.macvendor }}" + + # An optional file containing a pcap capture of the network traffic. This file is used + # for debugging purposes only. If you don't know what this is, you don't need it. + # Setting this to an empty string disables pcap recording. The file must be writable + # by the user running FTL (typically pihole). Failure to write to this file will + # prevent the DNS resolver from starting. The file is appended to if it already + # exists. + # + # Possible values are: + # + pcap = "{{ __pihole_effective.config.files.pcap }}" + + [files.log] + # The location of FTL's log file + # + # Possible values are: + # + ftl = "{{ __pihole_effective.config.files.log.ftl }}" + + # The log file used by the embedded dnsmasq DNS server + # + # Possible values are: + # + dnsmasq = "{{ __pihole_effective.config.files.log.dnsmasq }}" + + # The log file used by the webserver + # + # Possible values are: + # + webserver = "{{ __pihole_effective.config.files.log.webserver }}" + +[misc] + # Using privacy levels you can specify which level of detail you want to see in your + # Pi-hole statistics. Changing this setting will trigger a restart of FTL + # + # Possible values are: + # - 0 + # Don't hide anything, all statistics are available. + # - 1 + # Hide domains. This setting disables Top Domains and Top Ads + # - 2 + # Hide domains and clients. This setting disables Top Domains, Top Ads, Top + # Clients and Clients over time. + # - 3 + # Anonymize everything. This setting disables almost any statistics and query + # analysis. There will be no long-term database logging and no Query Log. You + # will also lose most regex features. + privacylevel = {{ __pihole_effective.config.misc.privacylevel }} + + # During startup, in some configurations, network interfaces appear only late during + # system startup and are not ready when FTL tries to bind to them. Therefore, you may + # want FTL to wait a given amount of time before trying to start the DNS revolver. + # This setting takes any integer value between 0 and 300 seconds. To prevent delayed + # startup while the system is already running and FTL is restarted, the delay only + # takes place within the first 180 seconds (hard-coded) after booting. + delay_startup = {{ __pihole_effective.config.misc.delay_startup }} + + # Set niceness of pihole-FTL. Defaults to -10 and can be disabled altogether by setting + # a value of -999. The nice value is an attribute that can be used to influence the + # CPU scheduler to favor or disfavor a process in scheduling decisions. The range of + # the nice value varies across UNIX systems. On modern Linux, the range is -20 (high + # priority = not very nice to other processes) to +19 (low priority). + nice = {{ __pihole_effective.config.misc.nice }} + + # Should FTL translate its own stack addresses into code lines during the bug + # backtrace? This improves the analysis of crashed significantly. It is recommended to + # leave the option enabled. This option should only be disabled when addr2line is + # known to not be working correctly on the machine because, in this case, the + # malfunctioning addr2line can prevent from generating any backtrace at all. + addr2line = {{ __pihole_effective.config.misc.addr2line }} + + # Should FTL load additional dnsmasq configuration files from /etc/dnsmasq.d/? + # Warning: This is an advanced setting and should only be used with care. + # Incorrectly formatted or config files specifying options which can only be defined + # once can result in conflicts with the automatic configuration of Pi-hole (see + # /etc/pihole/dnsmasq.conf) and may stop DNS resolution from working. + etc_dnsmasq_d = {{ __pihole_effective.config.misc.etc_dnsmasq_d }} + + # Additional lines to inject into the generated dnsmasq configuration. + # Warning: This is an advanced setting and should only be used with care. Incorrectly + # formatted or duplicated lines as well as lines conflicting with the automatic + # configuration of Pi-hole can break the embedded dnsmasq and will stop DNS resolution + # from working. + # Use this option with extra care. + # + # Possible values are: + # array of valid dnsmasq config line options + dnsmasq_lines = [ {{ '\"' + __pihole_effective.config.misc.dnsmasq_lines | join('\", \"') + '\"' }} ] + + # Log additional information about queries and replies to pihole.log + # When this setting is enabled, the log has extra information at the start of each + # line. This consists of a serial number which ties together the log lines associated + # with an individual query, and the IP address of the requestor. This setting is only + # effective if dns.queryLogging is enabled, too. This option is only useful for + # debugging and is not recommended for normal use. + extraLogging = {{ __pihole_effective.config.misc.extraLogging }} + + # Put configuration into read-only mode. This will prevent any changes to the + # configuration file via the API or CLI. This setting useful when a configuration is + # to be forced/modified by some third-party application (like infrastructure-as-code + # providers) and should not be changed by any means. + readOnly = {{ __pihole_effective.config.misc.readOnly }} + + [misc.check] + # Pi-hole is very lightweight on resources. Nevertheless, this does not mean that you + # should run Pi-hole on a server that is otherwise extremely busy as queuing on the + # system can lead to unnecessary delays in DNS operation as the system becomes less + # and less usable as the system load increases because all resources are permanently + # in use. To account for this, FTL regularly checks the system load. To bring this to + # your attention, FTL warns about excessive load when the 15 minute system load + # average exceeds the number of cores. + # This check can be disabled with this setting. + load = {{ __pihole_effective.config.misc.check.load }} + + # FTL stores history in shared memory to allow inter-process communication with forked + # dedicated TCP workers. If FTL runs out of memory, it cannot continue to work as + # queries cannot be analyzed any further. Hence, FTL checks if enough shared memory is + # available on your system and warns you if this is not the case. + # By default, FTL warns if the shared-memory usage exceeds 90%. You can set any + # integer limit between 0 to 100 (interpreted as percentages) where 0 means that + # checking of shared-memory usage is disabled. + shmem = {{ __pihole_effective.config.misc.check.shmem }} + + # FTL stores its long-term history in a database file on disk. Furthermore, FTL stores + # log files. By default, FTL warns if usage of the disk holding any crucial file + # exceeds 90%. You can set any integer limit between 0 to 100 (interpreted as + # percentages) where 0 means that checking of disk usage is disabled. + disk = {{ __pihole_effective.config.misc.check.disk }} + +[debug] + # Print debugging information about database actions. This prints performed SQL + # statements as well as some general information such as the time it took to store the + # queries and how many have been saved to the database. + database = {{ __pihole_effective.config.debug.database }} + + # Prints a list of the detected interfaces on the startup of pihole-FTL. Also, prints + # whether these interfaces are IPv4 or IPv6 interfaces. + networking = {{ __pihole_effective.config.debug.networking }} + + # Print information about shared memory locks. Messages will be generated when waiting, + # obtaining, and releasing a lock. + locks = {{ __pihole_effective.config.debug.locks }} + + # Print extensive query information (domains, types, replies, etc.). This has always + # been part of the legacy debug mode of pihole-FTL. + queries = {{ __pihole_effective.config.debug.queries }} + + # Print flags of queries received by the DNS hooks. Only effective when DEBUG_QUERIES + # is enabled as well. + flags = {{ __pihole_effective.config.debug.flags }} + + # Print information about shared memory buffers. Messages are either about creating or + # enlarging shmem objects or string injections. + shmem = {{ __pihole_effective.config.debug.shmem }} + + # Print information about garbage collection (GC): What is to be removed, how many have + # been removed and how long did GC take. + gc = {{ __pihole_effective.config.debug.gc }} + + # Print information about ARP table processing: How long did parsing take, whether read + # MAC addresses are valid, and if the macvendor.db file exists. + arp = {{ __pihole_effective.config.debug.arp }} + + # Controls if FTLDNS should print extended details about regex matching into FTL.log. + regex = {{ __pihole_effective.config.debug.regex }} + + # Print extra debugging information concerning API calls. This includes the request, + # the request parameters, and the internal details about how the algorithms decide + # which data to present and in what form. This very verbose output should only be used + # when debugging specific API issues and can be helpful, e.g., when a client cannot + # connect due to an obscure API error. Furthermore, this setting enables logging of + # all API requests (auth log) and details about user authentication attempts. + api = {{ __pihole_effective.config.debug.api }} + + # Print extra debugging information about TLS connections. This includes the TLS + # version, the cipher suite, the certificate chain and much more. This very verbose + # output should only be used when debugging specific TLS issues and can be helpful, + # e.g., when a client cannot connect due to an obscure TLS error as modern browsers do + # not provide much information about the underlying TLS connection and most often give + # only very generic error messages without much/any underlying technical information. + tls = {{ __pihole_effective.config.debug.tls }} + + # Print information about overTime memory operations, such as initializing or moving + # overTime slots. + overtime = {{ __pihole_effective.config.debug.overtime }} + + # Print information about status changes for individual queries. This can be useful to + # identify unexpected unknown queries. + status = {{ __pihole_effective.config.debug.status }} + + # Print information about capabilities granted to the pihole-FTL process. The current + # capabilities are printed on receipt of SIGHUP, i.e., the current set of capabilities + # can be queried without restarting pihole-FTL (by setting DEBUG_CAPS=true and + # thereafter sending killall -HUP pihole-FTL). + caps = {{ __pihole_effective.config.debug.caps }} + + # Print information about DNSSEC activity + dnssec = {{ __pihole_effective.config.debug.dnssec }} + + # FTL uses dynamically allocated vectors for various tasks. This config option enables + # extensive debugging information such as information about allocation, referencing, + # deletion, and appending. + vectors = {{ __pihole_effective.config.debug.vectors }} + + # Extensive information about hostname resolution like which DNS servers are used in + # the first and second hostname resolving tries (only affecting internally generated + # PTR queries). + resolver = {{ __pihole_effective.config.debug.resolver }} + + # Print debugging information about received EDNS(0) data. + edns0 = {{ __pihole_effective.config.debug.edns0 }} + + # Log various important client events such as change of interface (e.g., client + # switching from WiFi to wired or VPN connection), as well as extensive reporting + # about how clients were assigned to its groups. + clients = {{ __pihole_effective.config.debug.clients }} + + # Log information related to alias-client processing. + aliasclients = {{ __pihole_effective.config.debug.aliasclients }} + + # Log information regarding FTL's embedded event handling queue. + events = {{ __pihole_effective.config.debug.events }} + + # Log information about script helpers, e.g., due to dhcp-script. + helper = {{ __pihole_effective.config.debug.helper }} + + # Print config parsing details + config = {{ __pihole_effective.config.debug.config }} + + # Debug monitoring of /etc/pihole filesystem events + inotify = {{ __pihole_effective.config.debug.inotify }} + + # Debug monitoring of the webserver (CivetWeb) events + webserver = {{ __pihole_effective.config.debug.webserver }} + + # Temporary flag that may print additional information. This debug flag is meant to be + # used whenever needed for temporary investigations. The logged content may change + # without further notice at any time. + extra = {{ __pihole_effective.config.debug.extra }} + + # Reserved debug flag + reserved = {{ __pihole_effective.config.debug.reserved }} + + # Print information about NTP synchronization + ntp = {{ __pihole_effective.config.debug.ntp }} + + # Print information about netlink communication and parsing + netlink = {{ __pihole_effective.config.debug.netlink }} + + # Set all debug flags at once. This is a convenience option to enable all debug flags + # at once. Note that this option is not persistent, setting it to true will enable all + # *remaining* debug flags but unsetting it will disable *all* debug flags. + all = {{ __pihole_effective.config.debug.all }} diff --git a/tests/sanity/ignore-common.txt b/tests/sanity/ignore-common.txt index c73591b..bc97812 100644 --- a/tests/sanity/ignore-common.txt +++ b/tests/sanity/ignore-common.txt @@ -1,4 +1,5 @@ COPYING no-smart-quotes +LICENSES/EUPL-1.2.txt no-smart-quotes LICENSES/GPL-3.0-only.txt no-smart-quotes LICENSES/GPL-3.0-or-later.txt no-smart-quotes roles/docker/molecule/default/files/build-stub-repo.sh shebang # run by the docker scenario, not by Ansible