Skip to content

Commit

Permalink
Merge pull request #36 from sozialinfo/main
Browse files Browse the repository at this point in the history
feat(prometheus): add subdomain for prometehus to nginx config
  • Loading branch information
janikvonrotz authored Feb 5, 2025
2 parents d0f61a2 + 1540f69 commit 1904719
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions roles/nginx/tasks/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
volumes: "{{ nginx_volumes }}"
networks:
- name: "{{ docker_network_name }}"
network_mode: bridge
log_driver: "{{ docker_log_driver }}"
log_options:
max-size: "{{ docker_log_max_size }}"
Expand Down
2 changes: 2 additions & 0 deletions roles/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ prometheus_port: 127.0.0.1:9999 # default: 127.0.0.1:9090
prometheus_retention_time: "30d" # default: "15d"
prometheus_etc_hosts: # defaults: {}
"server.example.com": 10.42.5.2
prometheus_proxy_basic_auth_username: metric # default: prometheus
prometheus_proxy_basic_auth_password: # default: "{{ vault_prometheus_proxy_basic_auth_password }}"

prometheus_node_exporter_basic_auth_username: node-exporter
prometheus_node_exporter_basic_auth_password: # default: "{{ vault_prometheus_node_exporter_basic_auth_password }}"
Expand Down
2 changes: 2 additions & 0 deletions roles/prometheus/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ prometheus_volume_name: "{{ prometheus_hostname }}"
prometheus_data_dir: /usr/share/{{ prometheus_hostname }}
prometheus_hosts: "{{ groups['all'] }}"
prometheus_etc_hosts: {}
prometheus_proxy_basic_auth_username: prometheus
prometheus_proxy_basic_auth_password: "{{ vault_prometheus_proxy_basic_auth_password }}"
prometheus_retention_time: 15d
prometheus_alertmanager_basic_auth_password: "{{ vault_prometheus_alertmanager_basic_auth_password }}"
prometheus_node_exporter_basic_auth_password: "{{ vault_prometheus_node_exporter_basic_auth_password }}"
Expand Down
7 changes: 7 additions & 0 deletions roles/prometheus/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
when: prometheus_image is defined
tags:
- prometheus

- name: Include {{ role_name }} nginx config tasks
ansible.builtin.include_tasks: "{{ role_name }}_nginx_config.yml"
when: prometheus_proxy_basic_auth_password is defined
tags:
- prometheus
- prometheus_nginx_config
16 changes: 16 additions & 0 deletions roles/prometheus/tasks/prometheus_nginx_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Ensure nginx data dir exists
ansible.builtin.file:
path: "{{ nginx_data_dir }}/proxies"
state: directory

- name: Configure user access for {{ role_name }}
community.general.htpasswd:
path: "{{ nginx_data_dir }}/proxies/prometheus.htpasswd"
name: "{{ prometheus_proxy_basic_auth_username }}"
password: "{{ prometheus_proxy_basic_auth_password }}"

- name: Copy nginx {{ role_name }} conf
ansible.builtin.template:
src: prometheus.nginx
dest: "{{ nginx_data_dir }}/proxies/prometheus.nginx"
6 changes: 6 additions & 0 deletions roles/prometheus/templates/prometheus.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
location / {
auth_basic "{{ prometheus_proxy_basic_auth_username }}";
auth_basic_user_file /etc/nginx/conf.d/proxies/prometheus.htpasswd;
proxy_pass http://{{ prometheus_hostname }}:9090;
include /etc/nginx/conf.d/proxy-params.conf;
}

0 comments on commit 1904719

Please sign in to comment.