Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prometheus): add subdomain for prometehus to nginx config #36

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}