From 925f1a762d48c08f9cbe323bc5a4ea5318b2adca Mon Sep 17 00:00:00 2001 From: Camille Prugnard Date: Thu, 30 Sep 2021 12:25:21 +0200 Subject: [PATCH] move defaults vars to defaults directory --- defaults/main.yml | 19 +++++++++++++++++++ tasks/prometheus.yml | 4 ++-- templates/conf/prometheus-mongodb-exporter.j2 | 4 ++-- .../conf/prometheus-postgres-exporter.j2 | 2 +- templates/conf/prometheus.yml.j2 | 10 +++++----- .../prometheus-postgres-exporter.service.j2 | 2 +- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index ed97d53..ae37060 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1 +1,20 @@ --- +awh_services_docker_pull: "no" + +prometheus_exporter_packages: [] + +prometheus_mongodb_exporter_database: "database" +prometheus_mongodb_exporter_host: "localhost" +prometheus_mongodb_exporter_port: 27017 + +prometheus_postgres_exporter_host: "/var/run/postgresql/" +prometheus_postgres_exporter_sslmode: "disable" +prometheus_postgres_exporter_user: "postgres" + +prometheus_server_enable: false +prometheus_server_global_evaluation_interval: 15 +prometheus_server_global_scrape_interval: 15 +prometheus_server_job_name: "prometheus" +prometheus_server_scrape_interval: 5 +prometheus_server_scrape_timeout: 5 +prometheus_server_version: "latest" diff --git a/tasks/prometheus.yml b/tasks/prometheus.yml index 8092431..eeda129 100644 --- a/tasks/prometheus.yml +++ b/tasks/prometheus.yml @@ -43,7 +43,7 @@ docker_container: name: prometheus hostname: '{{ inventory_hostname }}' - image: prom/prometheus:{{ prometheus_server_version|default("latest") }} + image: prom/prometheus:{{ prometheus_server_version }} volumes: - /etc/prometheus/:/etc/prometheus/ - prometheus_data:/prometheus @@ -61,7 +61,7 @@ log_options: tag: docker_prometheus restart_policy: 'unless-stopped' - pull: '{{ awh_services_docker_pull|default("no") }}' + pull: '{{ awh_services_docker_pull }}' tags: - prometheus notify: diff --git a/templates/conf/prometheus-mongodb-exporter.j2 b/templates/conf/prometheus-mongodb-exporter.j2 index a4585ae..740314f 100644 --- a/templates/conf/prometheus-mongodb-exporter.j2 +++ b/templates/conf/prometheus-mongodb-exporter.j2 @@ -1,6 +1,6 @@ # {{ ansible_managed }} {% if (prometheus_mongodb_exporter_user is defined) and (prometheus_mongodb_exporter_pass is defined) %} -MONGODB_URI=mongodb://{{ prometheus_mongodb_exporter_user }}:{{ prometheus_mongodb_exporter_pass }}@{{ prometheus_mongodb_exporter_host|default("localhost") }}:{{ prometheus_mongodb_exporter_port|default("27017") }}/{{ prometheus_mongodb_exporter_database|default("admin") }} +MONGODB_URI=mongodb://{{ prometheus_mongodb_exporter_user }}:{{ prometheus_mongodb_exporter_pass }}@{{ prometheus_mongodb_exporter_host }}:{{ prometheus_mongodb_exporter_port }}/{{ prometheus_mongodb_exporter_database }} {% else %} -MONGODB_URI=mongodb://{{ prometheus_mongodb_exporter_host|default("localhost") }}:{{ prometheus_mongodb_exporter_port|default("27017") }}/{{ prometheus_mongodb_exporter_database|default("admin") }} +MONGODB_URI=mongodb://{{ prometheus_mongodb_exporter_host }}:{{ prometheus_mongodb_exporter_port }}/{{ prometheus_mongodb_exporter_database }} {% endif %} diff --git a/templates/conf/prometheus-postgres-exporter.j2 b/templates/conf/prometheus-postgres-exporter.j2 index c59ce6f..e7f1355 100644 --- a/templates/conf/prometheus-postgres-exporter.j2 +++ b/templates/conf/prometheus-postgres-exporter.j2 @@ -1,2 +1,2 @@ # {{ ansible_managed }} -DATA_SOURCE_NAME="user={{ prometheus_postgres_exporter_user|default("postgres") }} host={{ prometheus_postgres_exporter_host|default("/var/run/postgresql/") }} sslmode={{ prometheus_postgres_exporter_sslmode|default("disable") }}" +DATA_SOURCE_NAME="user={{ prometheus_postgres_exporter_user }} host={{ prometheus_postgres_exporter_host }} sslmode={{ prometheus_postgres_exporter_sslmode }}" diff --git a/templates/conf/prometheus.yml.j2 b/templates/conf/prometheus.yml.j2 index 274968b..2b6ef93 100644 --- a/templates/conf/prometheus.yml.j2 +++ b/templates/conf/prometheus.yml.j2 @@ -1,8 +1,8 @@ # {{ ansible_managed }} global: - scrape_interval: {{ prometheus_server_global_scrape_interval | default(15) }}s # Set the scrape interval to every 15 seconds. Default is every 1 minute. - evaluation_interval: {{ prometheus_server_global_evaluation_interval | default(15) }}s # Evaluate rules every 15 seconds. The default is every 1 minute. + scrape_interval: {{ prometheus_server_global_scrape_interval }}s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: {{ prometheus_server_global_evaluation_interval }}s # Evaluate rules every 15 seconds. The default is every 1 minute. # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). @@ -19,11 +19,11 @@ rule_files: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=` to any timeseries scraped from this config. - - job_name: '{{ prometheus_server_job_name | default("prometheus") }}' + - job_name: '{{ prometheus_server_job_name }}' # Override the global default and scrape targets from this job every 5 seconds. - scrape_interval: {{ prometheus_server_scrape_interval | default(5) }}s - scrape_timeout: {{ prometheus_server_scrape_timeout | default(5) }}s + scrape_interval: {{ prometheus_server_scrape_interval }}s + scrape_timeout: {{ prometheus_server_scrape_timeout }}s # metrics_path defaults to '/metrics' # scheme defaults to 'http'. diff --git a/templates/systemd/prometheus-postgres-exporter.service.j2 b/templates/systemd/prometheus-postgres-exporter.service.j2 index 204a439..28c9092 100644 --- a/templates/systemd/prometheus-postgres-exporter.service.j2 +++ b/templates/systemd/prometheus-postgres-exporter.service.j2 @@ -4,7 +4,7 @@ After=network.target [Service] Type=simple -User={{ prometheus_postgres_exporter_user|default("postgres") }} +User={{ prometheus_postgres_exporter_user }} ExecStart=/usr/local/bin/prometheus-postgres-exporter EnvironmentFile=/etc/default/prometheus-postgres-exporter