Files
Kamino/roles/pihole/README.md
T
Defame1297 66628635b9 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
2026-11-25 18:10:59 +00:00

7.4 KiB

pihole

Installs Pi-hole 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, 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 <repo.path>/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

- 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.