Author: HomeSec Explorer
License: MIT
Tags: pihole, dns, adblock, local_dns, selfhosted, homelab, privacy
This role installs, configures, and manages Pi-hole using Ansible. It supports version 6.x and sets up the complete config file - including DNS,DHCP, NTP, and web interface - while also managing blocklists and domainlists directly via the Pi-hole database.
By default, Pi-hole is configured to use a local cloudflared instance as its upstream DNS-over-HTTPS (DoH) resolver.
You can deploy and manage this DoH proxy using the HomeSecExplorer.cloudflared role, or customize your DNS upstreams via the hseph_upstreams variable.
E.g. cloudflare:
hseph_upstreams:
- '1.1.1.1'
- '1.0.0.1'Ideal for self-hosted networks, homelabs, or as a privacy-focused DNS resolver.
- Ansible
>= 2.13 - Root (or sudo) privileges on the target host
- Internet access for Pi-hole system
See the Pi-hole system requirements for official OS support details.
- Debian 11 (Bullseye), 12 (Bookworm), 13 (Trixie)
- Ubuntu 22.04 (Jammy), 24.04 (Noble)
⚠️ The OS compatibility check (hseph_os_check) ensures supported platforms for this role - not official Pi-hole support.
Legend: ✅ manual test passed - 🔁 covered in CI - ⚪ not tested
| Distro | Version | Manually verified | CI | Notes |
|---|---|---|---|---|
| Debian | 13 | ✅ | 🔁 | |
| Debian | 12 | ✅ | 🔁 | |
| Debian | 11 | ⚪ | 🔁 | |
| Ubuntu | 24.04 | ✅ | 🔁 | |
| Ubuntu | 22.04 | ⚪ | 🔁 |
⚙️ For all changeable variables see
defaults/main.yml.
hseph_pw_hash: '' # Hashed password for web UI (takes precedence)
hseph_pw_plain: 'Passw0rd' # Plaintext fallback (do not use in production)hseph_install: true # Install Pi-hole if not present
hseph_update: true # Run Pi-hole update if already installed
hseph_configure: true # Apply Pi-hole configuration (TOML, DNS, blocklists)
hseph_os_check: true # Validate if the target OS is supported before proceedinghseph_pihole_blocklist:
- url: 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts'
enable: '1'
comment: 'default'
- url: 'https://adaway.org/hosts.txt'
enable: '1'
comment: 'Ads'hseph_pihole_domainlist:
- domain: 'example.com'
type: '1'
enabled: '1'
comment: 'Block example.com'Automatically generates DNS records for inventory hosts (when enabled and using
hostname ansible_host=IPformat)
hseph_local_dns_entry: true
hseph_dns_for_inventory: true
hseph_dns_file:
- template: 'example_dns.conf.j2'
dest: '00.{{ hseph_dns_domain }}.conf'- Example inventory:
-
[dns_servers] pihole1 ansible_host=192.168.1.252
-
install– Install Pi-hole and dependenciesuninstall– Uninstall Pi-hole and dependenciesupdate– Update Pi-hole to the latest versionconfig– Apply Pi-hole settings (TOML, DNS, blocklists)
From Ansible Galaxy (recommended):
-
ansible-galaxy install HomeSecExplorer.pihole
Or manually (via Git):
-
git clone https://github.com/HomeSecExplorer/ansible-role-pihole.git roles/HomeSecExplorer.pihole
- name: Deploy Pi-hole with full configuration
hosts: dns_servers
become: true
roles:
- role: HomeSecExplorer.piholeMIT
HomeSec Explorer
🔗 YouTube Channel
If this role was helpful, drop a ⭐ on GitHub, subscribe on YouTube or Sponsor me!