From d83c9a50fa29f51e3195929c62f4946cab8c50c5 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 15 Oct 2021 18:24:52 +0200 Subject: prometheus: fix smartmon textfile collector --- .../prometheus/exporter/node/tasks/main.yml | 4 ++-- .../node/tasks/textfile_collector_generic.yml | 24 ++++++++++++++++++++++ .../node/tasks/textfile_collector_script.yml | 24 ---------------------- .../node/tasks/textfile_collector_smartmon.yml | 21 +++++++++++++++++++ 4 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_generic.yml delete mode 100644 roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_script.yml create mode 100644 roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_smartmon.yml (limited to 'roles/monitoring/prometheus/exporter/node/tasks') diff --git a/roles/monitoring/prometheus/exporter/node/tasks/main.yml b/roles/monitoring/prometheus/exporter/node/tasks/main.yml index 2811c759..27bf3a4d 100644 --- a/roles/monitoring/prometheus/exporter/node/tasks/main.yml +++ b/roles/monitoring/prometheus/exporter/node/tasks/main.yml @@ -43,10 +43,10 @@ when: ansible_pkg_mgr == "apt" vars: textfile_collector_name: "apt" - include_tasks: textfile_collector_script.yml + include_tasks: textfile_collector_generic.yml - name: install all other textfile collector scripts loop: "{{ prometheus_exporter_node_textfile_collector_scripts }}" loop_control: loop_var: textfile_collector_name - include_tasks: textfile_collector_script.yml + include_tasks: "{{ q('first_found', ['textfile_collector_' + textfile_collector_name + '.yml', 'textfile_collector_generic.yml'] ) | first }}" diff --git a/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_generic.yml b/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_generic.yml new file mode 100644 index 00000000..80390a15 --- /dev/null +++ b/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_generic.yml @@ -0,0 +1,24 @@ +--- +- name: install the collector script + copy: + src: "{{ textfile_collector_name }}" + dest: "/usr/local/share/prometheus-node-exporter/{{ textfile_collector_name }}" + mode: 0755 + +- name: install systemd service units + loop: + - service + - timer + template: + src: "textfile-collector-scripts/{{ textfile_collector_name }}.{{ item }}.j2" + dest: "/etc/systemd/system/prometheus-node-exporter_{{ textfile_collector_name }}.{{ item }}" + +- name: make sure the systemd timer is enabled and started + systemd: + daemon_reload: yes + name: "prometheus-node-exporter_{{ textfile_collector_name }}.timer" + state: started + enabled: yes + + +## TODO: install deps for textfile collectors: i.e. smartmontools for collector smartmon diff --git a/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_script.yml b/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_script.yml deleted file mode 100644 index 80390a15..00000000 --- a/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_script.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- name: install the collector script - copy: - src: "{{ textfile_collector_name }}" - dest: "/usr/local/share/prometheus-node-exporter/{{ textfile_collector_name }}" - mode: 0755 - -- name: install systemd service units - loop: - - service - - timer - template: - src: "textfile-collector-scripts/{{ textfile_collector_name }}.{{ item }}.j2" - dest: "/etc/systemd/system/prometheus-node-exporter_{{ textfile_collector_name }}.{{ item }}" - -- name: make sure the systemd timer is enabled and started - systemd: - daemon_reload: yes - name: "prometheus-node-exporter_{{ textfile_collector_name }}.timer" - state: started - enabled: yes - - -## TODO: install deps for textfile collectors: i.e. smartmontools for collector smartmon diff --git a/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_smartmon.yml b/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_smartmon.yml new file mode 100644 index 00000000..8da763cd --- /dev/null +++ b/roles/monitoring/prometheus/exporter/node/tasks/textfile_collector_smartmon.yml @@ -0,0 +1,21 @@ +--- +- name: install smartmontools + apt: + name: smartmontools + state: present + +- name: make sure smartd service is stopped and masked + when: (ansible_distribution == 'Debian' and (ansible_distribution_major_version | int) < 11) or (ansible_distribution == 'Ubuntu' and (ansible_distribution_major_version | int) < 20) + systemd: + name: smartd.service + state: stopped + masked: yes + +- name: make sure smartmontools service is stopped and masked + systemd: + name: smartmontools.service + state: stopped + masked: yes + +- name: install the smartmon textfile collector script + include_tasks: textfile_collector_generic.yml -- cgit v1.2.3