Skip to content

Forinil/ansible-pihole

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pi-Hole

This Ansible role automates the installation of Pi-Hole on your Ubuntu Jammy (22.04) or Focal (20.04) server.

Usage

Please feel free to redefine any variable in the pihole_default dict, but you must do so by creating a dict named pihole somewhere with higher priority, such as group vars, host vars, or play vars.

Note that you only need to specify the part(s) of this dict that you wish to edit. For example, to reset the minimally necessary variables, add the following somewhere as per above:

pihole:
  setupVars:
    webpassword: "abettermoreprivatepassword"
    dns_servers:
      - "127.0.0.1#5353"

To understand how the pihole dict is merged with pihole_default, see ./merge-defaults.yml (it is simple a recursive merge using the combine() filter, and works reliably in my experience).

But please note that unless you enable hash merging globally, this approach (with a single dict) limits you to specifying your pihole dict in one place only. For example, you must not set pihole.ftlconfig.privacylevel in host vars and pihole.setupVars.dns_servers in group vars (in such a case, only values set in host vars would become part of the finally used pihole). This is annoying, I agree, but globally enabling merging of dicts is considered poor practice as far as I can understand.

Set the web-admin password

You must supply your own password to pihole.setupVars.webpassword. Note that this role takes care of the double-hashing that Pi-Hole requires.

For reference, here is one way to double-hash a password provided from stdin:

echo -n somelongandsecretstringofyourown | sha256sum | awk '{printf "%s",$1 }' | sha256sum

How to remotely access the Pi-Hole web-admin

Assuming you can SSH into the Pi-Hole host, just open up an SSH port forward

ssh -L 8800:localhost:80 alexandria

where we forward a local unprivileged port (e.g., 8800), to port 80 on the Pi-Hole host (in this alexandria is configured in ~/.ssh/config).

In a browser on your local machine, go to http://localhost:8800/admin. Voilá!

PS. The ssh forward command above can be improved by adding suitable flags. Right now, it opens a terminal session, which is unnecessary.

The FTL database can get quite large in a year

By default Pi-Hole saves /etc/pihole/pihole-FTL.db for a year, which for a Raspberry Pi running off of an SD card can become a significant chunk of space. On my DNS server it's currently >3GB, with /var/log/ using an additional 2GB.

To restrict the FTL database, set pihole.ftlconfig.maxdbdays to a value less than 365.

Links and notes

Unattended install

This role runs the Pi-Hole CLI install script in unattended mode. Instead of configuring Pi-Hole via interactive prompts in the CLI, we create setupVars.conf before running the unattended install script.

Web server alongside Pi-Hole (Heimdall in my case)

VPN server (Wireguard or Tailscale) alongside Pi-Hole

Ansible roles

Ansible roles that install Pi-Hole from Docker image

Suggestions

Sync Gravity across Pi-Hole instances

Sounds interesting, except I think I prefer each Pi-Hole to be independent. Perhaps I will change my mind down the road...

Should this role configure DNSMASQ custom config?

Perhaps draw inspiration from drew1kun role.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages