commit 348f7808624d1c8c58e851bed511e8d7cf01b7f0 Author: mathieu Date: Sun May 24 17:13:35 2026 +0200 feat: initial installation role for pihole diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8b42eb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.retry diff --git a/README.md b/README.md new file mode 100644 index 0000000..f8c9bb1 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# ansible-role-pihole + +Installs Pi-hole using the official unattended installer. A `setupVars.conf` +is written before the installer runs so no interactive prompts appear. + +The installer creates its own system users and manages its own services. + +## Requirements + +- Ansible >= 2.14 +- Debian or Ubuntu +- A static IP address on the target host + +## Role Variables + +| Variable | Default | Description | +|---|---|---| +| `pihole_interface` | `{{ ansible_default_ipv4.interface }}` | Network interface | +| `pihole_ipv4_address` | `{{ ansible_default_ipv4.address }}/{{ ansible_default_ipv4.prefix }}` | IP/CIDR | +| `pihole_dns_1` | `8.8.8.8` | Primary upstream DNS | +| `pihole_dns_2` | `8.8.4.4` | Secondary upstream DNS | +| `pihole_query_logging` | `"true"` | Enable query logging | +| `pihole_install_web_server` | `"true"` | Install lighttpd web server | +| `pihole_install_web_interface` | `"true"` | Install web admin interface | +| `pihole_lighttpd_enabled` | `"true"` | Enable lighttpd | +| `pihole_cache_size` | `10000` | DNS cache size | + +## Example Playbook + +```yaml +- hosts: dns_servers + roles: + - role: ansible-role-pihole + vars: + pihole_dns_1: 1.1.1.1 + pihole_dns_2: 1.0.0.1 +``` + +## License + +MIT diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e12e7bf --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,10 @@ +--- +pihole_interface: "{{ ansible_default_ipv4.interface }}" +pihole_ipv4_address: "{{ ansible_default_ipv4.address }}/{{ ansible_default_ipv4.prefix }}" +pihole_dns_1: 8.8.8.8 +pihole_dns_2: 8.8.4.4 +pihole_query_logging: "true" +pihole_install_web_server: "true" +pihole_install_web_interface: "true" +pihole_lighttpd_enabled: "true" +pihole_cache_size: 10000 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..6e6376c --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,13 @@ +--- +galaxy_info: + author: mathieu + description: Install Pi-hole via the official unattended installer + license: MIT + min_ansible_version: "2.14" + platforms: + - name: Debian + versions: [bullseye, bookworm] + - name: Ubuntu + versions: [focal, jammy, noble] + galaxy_tags: [pihole, dns, adblock] +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..3d63df4 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,62 @@ +--- +- name: Assert Debian-based distribution + ansible.builtin.assert: + that: + - ansible_os_family == 'Debian' + fail_msg: "ansible-role-pihole only supports Debian-based distributions" + +- name: Install Pi-hole prerequisites + ansible.builtin.apt: + name: + - curl + - git + - dhcpcd5 + state: present + update_cache: true + become: true + +- name: Create /etc/pihole directory + ansible.builtin.file: + path: /etc/pihole + state: directory + mode: '0755' + become: true + +- name: Write setupVars.conf for unattended installation + ansible.builtin.copy: + content: | + PIHOLE_INTERFACE={{ pihole_interface }} + IPV4_ADDRESS={{ pihole_ipv4_address }} + PIHOLE_DNS_1={{ pihole_dns_1 }} + PIHOLE_DNS_2={{ pihole_dns_2 }} + QUERY_LOGGING={{ pihole_query_logging }} + INSTALL_WEB_SERVER={{ pihole_install_web_server }} + INSTALL_WEB_INTERFACE={{ pihole_install_web_interface }} + LIGHTTPD_ENABLED={{ pihole_lighttpd_enabled }} + CACHE_SIZE={{ pihole_cache_size }} + DNS_FLUSHED_ON_RESTART=true + DNSSEC=false + TEMPERATUREUNIT=C + WEBUIBOXEDLAYOUT=traditional + API_PRIVACY_MODE=false + BLOCKING_ENABLED=true + dest: /etc/pihole/setupVars.conf + mode: '0644' + become: true + +- name: Download Pi-hole installer + ansible.builtin.get_url: + url: https://install.pi-hole.net + dest: /tmp/pihole-installer.sh + mode: '0755' + +- name: Run Pi-hole unattended installer + ansible.builtin.command: + cmd: /tmp/pihole-installer.sh --unattended + creates: /usr/local/bin/pihole + become: true + +- name: Remove Pi-hole installer script + ansible.builtin.file: + path: /tmp/pihole-installer.sh + state: absent