From e160b98f0ed992291f4a063c37cfd320cdad6579 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Tue, 4 Apr 2023 01:28:51 +0200 Subject: [PATCH] prometheus_node: collect textfiles --- roles/prometheus_node/handlers/main.yml | 10 +++++++ roles/prometheus_node/tasks/main.yml | 29 +++++++++++++++++++ roles/prometheus_node/templates/default.j2 | 7 +++++ .../templates/override.conf.j2 | 4 +++ 4 files changed, 50 insertions(+) create mode 100644 roles/prometheus_node/handlers/main.yml create mode 100644 roles/prometheus_node/templates/default.j2 create mode 100644 roles/prometheus_node/templates/override.conf.j2 diff --git a/roles/prometheus_node/handlers/main.yml b/roles/prometheus_node/handlers/main.yml new file mode 100644 index 0000000..a493fd5 --- /dev/null +++ b/roles/prometheus_node/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: Run daemon-reload + systemd: + daemon_reload: true + +- name: Restart prometheus-node-exporter + systemd: + name: prometheus-node-exporter.service + state: restarted +... diff --git a/roles/prometheus_node/tasks/main.yml b/roles/prometheus_node/tasks/main.yml index 087a698..04af608 100644 --- a/roles/prometheus_node/tasks/main.yml +++ b/roles/prometheus_node/tasks/main.yml @@ -6,12 +6,41 @@ - prometheus-node-exporter-collectors install_recommends: false # Do not install smartmontools +- name: Configure prometheus-node-exporter + template: + src: default.j2 + dest: /etc/default/prometheus-node-exporter + owner: root + group: root + mode: u=rw,g=r,o=r + notify: + - Restart prometheus-node-exporter + - name: Install smartmontools apt: name: smartmontools when: - "ansible_virtualization_role == 'host'" +- name: Create override directory + file: + path: /etc/systemd/system/prometheus-node-exporter.service.d + state: directory + owner: root + group: root + mode: u=rwx,g=rw,o=rw + +- name: Override prometheus-node-exporter.service + template: + src: override.conf.j2 + dest: /etc/systemd/system/prometheus-node-exporter.service.d/override.conf + owner: root + group: root + mode: u=rw,g=r,o=r + notify: + - Run daemon-reload + - Restart prometheus-node-exporter + - name: Enable prometheus-node-exporter systemd: name: prometheus-node-exporter diff --git a/roles/prometheus_node/templates/default.j2 b/roles/prometheus_node/templates/default.j2 new file mode 100644 index 0000000..6c3870e --- /dev/null +++ b/roles/prometheus_node/templates/default.j2 @@ -0,0 +1,7 @@ +{{ ansible_managed | comment }} + +{% if prometheus_node__text_dir is defined %} +ARGS="--collector.textfile.directory={{ prometheus_node__text_dir | quote }}" +{% else %} +ARGS="" +{% endif %} diff --git a/roles/prometheus_node/templates/override.conf.j2 b/roles/prometheus_node/templates/override.conf.j2 new file mode 100644 index 0000000..3b05667 --- /dev/null +++ b/roles/prometheus_node/templates/override.conf.j2 @@ -0,0 +1,4 @@ +{{ ansible_managed | comment }} + +[Service] +RuntimeDirectory=prometheus-node-exporter