diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-09-13 22:14:29 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-09-13 22:20:16 +0200 |
| commit | c10b52fb07dd4c92e827b64bf3ac673c69d9d14f (patch) | |
| tree | 057f20be613df0d8678e0d17a17f9439130d1f1e /roles/pihole/tasks | |
| parent | f15f59c6f49f48c7e24fabfc003ef9dcfe612e3a (diff) | |
Add pihole port configurations and integration with nginx
Diffstat (limited to 'roles/pihole/tasks')
| -rw-r--r-- | roles/pihole/tasks/main.yml | 23 |
1 files changed, 23 insertions, 0 deletions
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" |
