From c10b52fb07dd4c92e827b64bf3ac673c69d9d14f Mon Sep 17 00:00:00 2001 From: Ahmed Abdelhalim Date: Sat, 13 Sep 2025 22:14:29 +0200 Subject: Add pihole port configurations and integration with nginx --- roles/pihole/tasks/main.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'roles/pihole/tasks') diff --git a/roles/pihole/tasks/main.yml b/roles/pihole/tasks/main.yml index e0df5c2b..916200d6 100644 --- a/roles/pihole/tasks/main.yml +++ b/roles/pihole/tasks/main.yml @@ -106,3 +106,26 @@ dest: "/etc/resolv.conf" state: "link" force: true + +- name: "Create pihole nginx configurations" + become: true + when: pihole_by_nginx is defined and pihole_by_nginx != "" + ansible.builtin.copy: + content: | + location /admin/ { + proxy_pass http://127.0.0.1:{{ pihole_port }}/admin/; + } + location /api/ { + proxy_pass http://127.0.0.1:{{ pihole_port }}/api/; + } + dest: "/etc/nginx/conf.d/pihole.conf" + owner: "root" + group: "root" + mode: "0644" + backup: true + # workaround issue: https://github.com/ansible/ansible/issues/9112 + # ref: https://serverfault.com/a/811520 + validate: > + bash -c 'echo "events { worker_connections 2; } http { server { include %s; } }" > /tmp/nginx.conf; + sudo nginx -T -c /tmp/nginx.conf; ec=$?; rm -f /tmp/nginx.conf; exit $ec' + notify: "Restart nginx" -- cgit v1.2.3