Skip to content

Commit ef471b3

Browse files
authored
Merge pull request #2 from blalop/features/1
#1 Pi-Hole Exporter
2 parents d7203e3 + 380ffd0 commit ef471b3

File tree

12 files changed

+200
-33
lines changed

12 files changed

+200
-33
lines changed

README.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,22 @@
33
[![Build Status](https://travis-ci.com/blalop/pihole_role.svg?branch=main)](https://travis-ci.com/blalop/pihole_role)
44
[![Ansible Galaxy](https://img.shields.io/badge/galaxy-blalop.pihole_role-B62682.svg)](https://galaxy.ansible.com/blalop/pihole_role)
55

6-
This role installs pihole via installation script. Tested on Debian && Raspbian.
7-
8-
## Requirements
9-
10-
No special requirements.
6+
This role installs [Pi-Hole](https://pi-hole.net/) via installation script and (optionally) [eko](https://github.com/eko)'s [Pi-hole Exporter](https://github.com/eko/pihole-exporter).
117

8+
Made with [Idealista's cookiecutter template](https://github.com/idealista/cookiecutter-ansible-role).
129

13-
## Role vars
10+
## Requirements
1411

15-
| Variable | Default | Additional comments |
16-
| :--- | :--- | :--- |
17-
| `pihole_required_packages` | [procps] | |
18-
| `pihole_password` | pihole | Pihole web interface password |
19-
| `pihole_force_reinstall` | false | Forces reinstallation |
20-
| `pihole_lighttpd_port` | 80 | Web interface port |
21-
| `pihole_interface` | eth0 | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
22-
| `pihole_ipv4_address` | 0.0.0.0 | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
23-
| `pihole_ipv6_address` | 0:0:0:0:0:0 | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
24-
| `pihole_dns_1` | 8.8.8.8 | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
25-
| `pihole_dns_2` | 4.4.4.4 | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
26-
| `pihole_query_logging` | true | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
27-
| `pihole_web_server` | true | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
28-
| `pihole_web_interface` | true | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
29-
| `pihole_lighttpd_enabled` | true | [Pihole setup vars](https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533) |
12+
No special requirements. Use it in your playbook like this:
3013

14+
```
15+
- name: Configure services
16+
hosts: pi
17+
tags: services
18+
roles:
19+
- role: pihole
20+
tags: pihole
21+
```
3122

3223
## Testing
3324

defaults/main.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
22

3+
# Pi-hole
34
pihole_required_packages:
45
- procps
56

6-
pihole_password: pihole
7-
87
pihole_force_reinstall: false
98

9+
pihole_password: pihole
10+
1011
## Lighttpd config
1112
pihole_lighttpd_port: 80
1213

@@ -20,3 +21,40 @@ pihole_query_logging: true
2021
pihole_web_server: true
2122
pihole_web_interface: true
2223
pihole_lighttpd_enabled: true
24+
25+
# Pi-Hole Exporter
26+
pihole_exporter_install: true
27+
pihole_exporter_force_reinstall: false
28+
pihole_exporter_version: v0.0.11
29+
pihole_exporter_arch: linux-arm
30+
pihole_exporter_url: "https://github.com/eko/pihole-exporter/releases/download/{{ pihole_exporter_version }}/pihole_exporter-{{ pihole_exporter_arch }}"
31+
32+
## Options
33+
pihole_exporter_hostname: "127.0.0.1"
34+
pihole_exporter_port: 9617
35+
pihole_exporter_interval: 10s
36+
37+
## User & group
38+
pihole_exporter_user: pihole_exporter
39+
pihole_exporter_group: pihole_exporter
40+
41+
## Files
42+
pihole_exporter_exec_name: pihole_exporter
43+
pihole_exporter_bin_path: /opt/pihole_exporter
44+
pihole_exporter_logs_path: /var/log/pihole_exporter
45+
pihole_exporter_skeleton_paths:
46+
- "{{ pihole_exporter_bin_path }}"
47+
- "{{ pihole_exporter_logs_path }}"
48+
49+
## Service
50+
pihole_exporter_state: started
51+
pihole_exporter_enabled: yes
52+
pihole_exporter_private_tmp: yes
53+
pihole_exporter_documentation_link: https://github.com/eko/pihole-exporter
54+
pihole_exporter_max_files: 32768
55+
pihole_exporter_log_output: "{% if pihole_exporter_log_file is defined %} file:{{ pihole_exporter_log_file }} {% else %} journal{% endif %}"
56+
pihole_exporter_options:
57+
- "port {{ pihole_exporter_port }}"
58+
- "pihole_hostname {{ pihole_exporter_hostname }}"
59+
- "pihole_password {{ pihole_password }}"
60+
- "pihole_port {{ pihole_lighttpd_port }}"

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
systemd:
55
name: lighttpd
66
state: restarted
7+
8+
- name: restart pihole_exporter
9+
systemd:
10+
name: pihole_exporter
11+
state: restarted

molecule/default/group_vars/all.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
pihole_exporter_private_tmp: no
4+
pihole_exporter_arch: linux-amd64

molecule/default/molecule.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ platforms:
1717
- 67/udp
1818
- 80/tcp
1919
- 443/tcp
20+
- 9617/tcp
2021
published_ports:
2122
- 0.0.0.0:8080:80/tcp
23+
- 0.0.0.0:9617:9617/tcp
2224
capabilities:
2325
- SYS_ADMIN
2426
- NET_ADMIN

molecule/default/tests/test_app.yml renamed to molecule/default/tests/test_pihole.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ service:
99
running: true
1010

1111
http:
12-
"http://localhost:{{ pihole_lighttpd_port }}":
12+
http://localhost:
1313
status: 200
1414

1515
command:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
3+
service:
4+
pihole_exporter:
5+
enabled: true
6+
running: true
7+
8+
http:
9+
http://localhost:9617/metrics:
10+
status: 200
11+
body:
12+
- pihole_status{hostname="127.0.0.1"} 1
13+
14+
file:
15+
/usr/bin/pihole_exporter:
16+
exists: true
17+
owner: root
18+
group: root
19+
filetype: symlink
20+
/opt/pihole_exporter:
21+
exists: true
22+
owner: pihole_exporter
23+
group: pihole_exporter
24+
filetype: directory

molecule/default/verify.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
2-
# This is an example playbook to execute goss tests.
3-
# Tests need distributed to the appropriate ansible host/groups
4-
# prior to execution by `goss validate`.
52

63
- name: Verify pihole
74
hosts:
@@ -30,12 +27,16 @@
3027
until: download_goss is succeeded
3128
retries: 3
3229

33-
- name: Copy Goss tests to remote
34-
template:
35-
src: "{{ item }}"
36-
dest: "{{ goss_test_directory }}/{{ item | basename }}"
37-
with_fileglob:
38-
- "tests/test_*.yml"
30+
- name: Copy Goss Pi-hole tests to remote
31+
copy:
32+
src: tests/test_pihole.yml
33+
dest: "{{ goss_test_directory }}/test_pihole.yml"
34+
35+
- name: Copy Goss Pi-hole Exporter tests to remote
36+
copy:
37+
src: tests/test_pihole_exporter.yml
38+
dest: "{{ goss_test_directory }}/test_pihole_exporter.yml"
39+
when: pihole_exporter_install
3940

4041
- name: Register test files
4142
shell: "ls {{ goss_test_directory }}/test_*.yml"

tasks/exporter_install.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
3+
- name: Pi-hole Exporter | Ensure pihole_exporter group
4+
group:
5+
name: "{{ pihole_exporter_group }}"
6+
system: yes
7+
state: present
8+
9+
- name: Pi-hole Exporter | Ensure pihole_exporter user
10+
user:
11+
name: "{{ pihole_exporter_user }}"
12+
group: "{{ pihole_exporter_group }}"
13+
system: yes
14+
shell: /usr/sbin/nologin
15+
createhome: no
16+
17+
- name: Pi-hole Exporter | Ensure skeleton paths
18+
file:
19+
dest: "{{ item }}"
20+
owner: "{{ pihole_exporter_user }}"
21+
group: "{{ pihole_exporter_group }}"
22+
state: directory
23+
with_items:
24+
- "{{ pihole_exporter_skeleton_paths }}"
25+
26+
- name: Pi-hole Exporter | Check pihole_exporter version
27+
command: pihole_exporter --help
28+
register: pihole_exporter_check
29+
changed_when: false
30+
ignore_errors: true
31+
32+
- name: Pi-hole Exporter | Download package
33+
get_url:
34+
url: "{{ pihole_exporter_url }}"
35+
dest: "{{ pihole_exporter_bin_path }}/{{ pihole_exporter_exec_name }}-{{ pihole_exporter_version }}"
36+
owner: "{{ pihole_exporter_user }}"
37+
group: "{{ pihole_exporter_group }}"
38+
mode: "0755"
39+
when: pihole_exporter_force_reinstall or pihole_exporter_check is failed
40+
41+
- name: Pi-hole Exporter | Create symbolic link
42+
file:
43+
src: "{{ pihole_exporter_bin_path }}/{{ pihole_exporter_exec_name }}-{{ pihole_exporter_version }}"
44+
dest: /usr/bin/pihole_exporter
45+
state: link
46+
when: pihole_exporter_force_reinstall or pihole_exporter_check is failed

tasks/exporter_service.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
3+
- name: Pi-hole Exporter | Copy Daemon script
4+
template:
5+
src: pihole_exporter.service.j2
6+
dest: /etc/systemd/system/pihole_exporter.service
7+
mode: 0644
8+
owner: root
9+
group: root
10+
notify: restart pihole_exporter
11+
12+
- name: Pi-hole Exporter | Configuring service
13+
systemd:
14+
name: pihole_exporter
15+
state: "{{ pihole_exporter_state }}"
16+
enabled: "{{ pihole_exporter_enabled }}"
17+
daemon_reload: yes

tasks/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@
1818
include: config.yml
1919
tags:
2020
- pihole_configure
21+
22+
- name: Pi-hole Exporter | Install
23+
include: exporter_install.yml
24+
when: pihole_exporter_install
25+
tags:
26+
- pihole_exporter
27+
- pihole_exporter_install
28+
29+
- name: Pi-hole Exporter | Service
30+
include: exporter_service.yml
31+
when: pihole_exporter_install
32+
tags:
33+
- pihole_exporter
34+
- pihole_exporter_service

templates/pihole_exporter.service.j2

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{ ansible_managed | comment }}
2+
[Unit]
3+
Description=pihole_exporter
4+
Documentation={{ pihole_exporter_documentation_link }}
5+
Requires=network-online.target
6+
After=network-online.target
7+
8+
[Service]
9+
PrivateTmp={{ pihole_exporter_private_tmp }}
10+
User={{ pihole_exporter_user }}
11+
Group={{ pihole_exporter_group }}
12+
RuntimeDirectory=pihole_exporter
13+
LimitNOFILE={{ pihole_exporter_max_files }}
14+
15+
16+
ExecStart={{ pihole_exporter_exec_name }} {% for option in pihole_exporter_options %}-{{ option }} {% endfor %}
17+
18+
StandardOutput={{ pihole_exporter_log_output }}
19+
StandardError={{ pihole_exporter_log_output }}
20+
ExecReload=/bin/kill -HUP $MAINPID
21+
KillSignal=SIGTERM
22+
Restart=always
23+
24+
[Install]
25+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)