feat: initial installation role for pihole
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.retry
|
||||||
41
README.md
Normal file
41
README.md
Normal file
@@ -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
|
||||||
10
defaults/main.yml
Normal file
10
defaults/main.yml
Normal file
@@ -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
|
||||||
1
handlers/main.yml
Normal file
1
handlers/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
13
meta/main.yml
Normal file
13
meta/main.yml
Normal file
@@ -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: []
|
||||||
62
tasks/main.yml
Normal file
62
tasks/main.yml
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user