diff --git a/node_exporter/defaults/main.yml b/node_exporter/defaults/main.yml index a8c1c89c1fa91b8ba6a4c52680286d1bfaaa5d8f..b6743dfba0d8a56ce84b59da9549fd1a358d8763 100644 --- a/node_exporter/defaults/main.yml +++ b/node_exporter/defaults/main.yml @@ -1,3 +1,15 @@ --- node_exporter_args: "" force_smartmontools_on_vm_guest: false +node_exporter_needrestart: true +needrestart2prom_version: "ff8645ab287017d248ab946e09225b1a60fcbba1" +needrestart2prom_arch: >- + {% if ansible_architecture == "x86_64" -%} + amd64 + {%- elif ansible_architecture == "aarch64" -%} + arm64 + {%- elif ansible_architecture[:3] == "arm" -%} + {{ ansible_architecture[:5] }} + {%- else -%} + {{ ansible_architecture }} + {%- endif %} diff --git a/node_exporter/tasks/main.yml b/node_exporter/tasks/main.yml index e6d83a20237e9671f1b8134a1038622efd3e6974..eaffdfaed67d87428187ffd21790ef1c122b043a 100644 --- a/node_exporter/tasks/main.yml +++ b/node_exporter/tasks/main.yml @@ -59,3 +59,6 @@ - prometheus - prometheus-exporter - config + +- import_tasks: needrestart.yml + when: node_exporter_needrestart diff --git a/node_exporter/tasks/needrestart.yml b/node_exporter/tasks/needrestart.yml new file mode 100644 index 0000000000000000000000000000000000000000..32688cbe0c58dff5d7e0a7478a3de4ee8ce448e3 --- /dev/null +++ b/node_exporter/tasks/needrestart.yml @@ -0,0 +1,48 @@ +--- + +- name: Install needrestart + apt: + name: needrestart + state: present + tags: + - prometheus + - prometheus-exporter + +- name: Install needrestart2prom + get_url: + url: >- + https://git.fsmpi.rwth-aachen.de/api/v4/projects/233/packages/generic/needrestart2prom/{{ + needrestart2prom_version }}/needrestart2prom-{{ ansible_system|lower }}-{{ + needrestart2prom_arch }} + dest: /usr/local/bin/needrestart2prom + force: true + owner: root + group: root + mode: '0755' + tags: + - prometheus + - prometheus-exporter + +- name: Configure needrestart2prom cronjob PATH + cron: + cron_file: needrestart2prom + user: root + env: true + # Yes, this module actually works this way. + name: PATH + job: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + tags: + - prometheus + - prometheus-exporter + +- name: Configure needrestart2prom cronjob + cron: + cron_file: needrestart2prom + user: root + name: needrestart2prom + job: >- + /usr/local/bin/needrestart2prom -outfile + /var/lib/prometheus/node-exporter/needrestart.prom + tags: + - prometheus + - prometheus-exporter