mongosb - move secret to dedicated file

This commit is contained in:
Ludovic Cartier 2021-05-31 14:44:26 +02:00
parent ff0533ecd3
commit f86870ec3a
3 changed files with 18 additions and 5 deletions

View File

@ -38,6 +38,16 @@
notify: notify:
- 'prometheus | mongodb exporter | restart service' - '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' - name: 'prometheus | mongodb exporter | configure systemd to use service'
systemd: systemd:
daemon_reload: yes daemon_reload: yes

View File

@ -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 %}

View File

@ -4,11 +4,8 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
{% if (prometheus_mongodb_exporter_user is defined) and (prometheus_mongodb_exporter_pass is defined) %} ExecStart=/usr/local/bin/prometheus-mongodb-exporter
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") }} EnvironmentFile=/etc/mongodb-exporter.conf
{% 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 %}
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target