From f86870ec3a817257b657ad5e25a2841e44873d43 Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Mon, 31 May 2021 14:44:26 +0200 Subject: [PATCH] mongosb - move secret to dedicated file --- tasks/mongodb_exporter.yml | 10 ++++++++++ templates/conf/mongodb-exporter.conf.j2 | 6 ++++++ .../systemd/prometheus-mongodb-exporter.service.j2 | 7 ++----- 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 templates/conf/mongodb-exporter.conf.j2 diff --git a/tasks/mongodb_exporter.yml b/tasks/mongodb_exporter.yml index 5d0d98c..46612ad 100644 --- a/tasks/mongodb_exporter.yml +++ b/tasks/mongodb_exporter.yml @@ -38,6 +38,16 @@ notify: - 'prometheus | mongodb exporter | restart service' +- name: 'prometheus | mongodb exporter | configuration' + template: + src: conf/mongodb-exporter.conf.j2 + dest: /etc/mongodb-exporter.conf + owner: root + group: root + mode: 0600 + notify: + - 'prometheus | mongodb exporter | restart service' + - name: 'prometheus | mongodb exporter | configure systemd to use service' systemd: daemon_reload: yes diff --git a/templates/conf/mongodb-exporter.conf.j2 b/templates/conf/mongodb-exporter.conf.j2 new file mode 100644 index 0000000..a4585ae --- /dev/null +++ b/templates/conf/mongodb-exporter.conf.j2 @@ -0,0 +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") }} +{% else %} +MONGODB_URI=mongodb://{{ prometheus_mongodb_exporter_host|default("localhost") }}:{{ prometheus_mongodb_exporter_port|default("27017") }}/{{ prometheus_mongodb_exporter_database|default("admin") }} +{% endif %} diff --git a/templates/systemd/prometheus-mongodb-exporter.service.j2 b/templates/systemd/prometheus-mongodb-exporter.service.j2 index 12454af..50839ca 100644 --- a/templates/systemd/prometheus-mongodb-exporter.service.j2 +++ b/templates/systemd/prometheus-mongodb-exporter.service.j2 @@ -4,11 +4,8 @@ After=network.target [Service] Type=simple -{% if (prometheus_mongodb_exporter_user is defined) and (prometheus_mongodb_exporter_pass is defined) %} -ExecStart=/usr/local/bin/prometheus-mongodb-exporter --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") }} -{% else %} -ExecStart=/usr/local/bin/prometheus-mongodb-exporter --mongodb.uri=mongodb://{{ prometheus_mongodb_exporter_host|default("localhost") }}:{{ prometheus_mongodb_exporter_port|default("27017") }}/{{ prometheus_mongodb_exporter_database|default("admin") }} -{% endif %} +ExecStart=/usr/local/bin/prometheus-mongodb-exporter +EnvironmentFile=/etc/mongodb-exporter.conf [Install] WantedBy=multi-user.target