summaryrefslogtreecommitdiffstats
path: root/roles/pihole
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2026-06-18 16:30:12 +0200
committerAhmed Abdelhalim <[email protected]>2026-06-18 16:32:15 +0200
commit6a0fd11c6bd782a42b0b90d2f2365859a7953bb7 (patch)
treebf50fdd6ee47a5fde5bd3a05b96006138100dee8 /roles/pihole
parentc7a4dfce1ad0b545b05a8043e321ad49e48873a6 (diff)
Implement support for conditional proxy (nginx or caddy)
Diffstat (limited to 'roles/pihole')
-rw-r--r--roles/pihole/handlers/main.yml10
-rw-r--r--roles/pihole/tasks/main.yml15
-rw-r--r--roles/pihole/templates/pihole.caddy.j25
3 files changed, 28 insertions, 2 deletions
diff --git a/roles/pihole/handlers/main.yml b/roles/pihole/handlers/main.yml
index d839828e..a1318068 100644
--- a/roles/pihole/handlers/main.yml
+++ b/roles/pihole/handlers/main.yml
@@ -22,7 +22,17 @@
state: "restarted"
- name: "Restart nginx"
+ listen: "Restart proxy"
become: true
ansible.builtin.systemd_service:
name: "nginx"
state: "restarted"
+ when: proxy_type == "nginx"
+
+- name: "Restart caddy"
+ listen: "Restart proxy"
+ become: true
+ ansible.builtin.systemd_service:
+ name: "caddy"
+ state: "restarted"
+ when: proxy_type == "caddy"
diff --git a/roles/pihole/tasks/main.yml b/roles/pihole/tasks/main.yml
index 66208bdf..f6101632 100644
--- a/roles/pihole/tasks/main.yml
+++ b/roles/pihole/tasks/main.yml
@@ -151,7 +151,7 @@
- name: "Create pihole nginx vhost configuration"
become: true
- when: pihole_hostname | length > 0
+ when: proxy_type == "nginx" and pihole_hostname | length > 0
ansible.builtin.template:
src: "pihole.nginx.conf.j2"
dest: "/etc/nginx/vhosts.d/pihole.conf"
@@ -162,4 +162,15 @@
validate: >
bash -c 'echo "events { worker_connections 64; } http { include %s; }" > /tmp/nginx-vhost.conf;
sudo nginx -T -c /tmp/nginx-vhost.conf; ec=$?; rm -f /tmp/nginx-vhost.conf; exit $ec'
- notify: "Restart nginx"
+ notify: "Restart proxy"
+
+- name: "Create pihole caddy configuration"
+ become: true
+ when: proxy_type == "caddy" and pihole_hostname | length > 0
+ ansible.builtin.template:
+ src: "pihole.caddy.j2"
+ dest: "/etc/caddy/sites/pihole.caddy"
+ owner: "root"
+ group: "caddy"
+ mode: "0640"
+ notify: "Restart proxy"
diff --git a/roles/pihole/templates/pihole.caddy.j2 b/roles/pihole/templates/pihole.caddy.j2
new file mode 100644
index 00000000..ee62299e
--- /dev/null
+++ b/roles/pihole/templates/pihole.caddy.j2
@@ -0,0 +1,5 @@
+{{ pihole_hostname }} {
+ redir / /admin/ permanent
+ reverse_proxy /admin/* localhost:{{ pihole_port }}
+ reverse_proxy /api/* localhost:{{ pihole_port }}
+}