summaryrefslogtreecommitdiff
path: root/roles/monitoring/prometheus/exporter/node/tasks/main.yml
blob: 6f26d8d5a922aab0b449a3e9e1e35ec95e64f2b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
- name: generate apt pin file for exporter-node package
  when: prometheus_exporter_node_version is defined
  copy:
    dest: "/etc/apt/preferences.d/prom-exporter-node.pref"
    content: |
      Package: prom-exporter-node
      Pin: version {{ prometheus_exporter_node_version }}-1
      Pin-Priority: 1001

- name: remove apt pin file for exporter-node package
  when: prometheus_exporter_node_version is not defined
  file:
    path: "/etc/apt/preferences.d/prom-exporter-node.pref"
    state: absent

- name: install apt packages
  apt:
    name:
    - "prom-exporter-node{% if prometheus_exporter_node_version is defined %}={{ prometheus_exporter_node_version }}-1{% endif %}"
    - moreutils
    state: present
    allow_downgrade: yes
  notify: restart prometheus-node-exporter

- name: create directory for textfile collector
  file:
    path: /var/lib/prometheus-node-exporter/textfile-collector
    state: directory

- name: generate systemd service unit
  template:
    src: service.j2
    dest: /etc/systemd/system/prometheus-node-exporter.service
  notify: restart prometheus-node-exporter

- name: make sure prometheus-node-exporter is enabled and started
  systemd:
    name: prometheus-node-exporter.service
    daemon_reload: yes
    state: started
    enabled: yes

- name: register exporter
  copy:
    content: |
      location = /node {
          proxy_pass http://127.0.0.1:9100/metrics;
      }
    dest: /etc/prometheus/exporter/node.locations
  notify: reload nginx

- name: install common deps for textfile collector scripts
  apt:
    name: "{{ python_basename }}-prometheus-client"
    state: present

- name: create directory for textfile collector scripts
  file:
    path: /usr/local/share/prometheus-node-exporter
    state: directory

- name: install the apt_info textfile collector script
  when: prometheus_exporter_node_install_apt_info_textfile_collector_script
  vars:
    textfile_collector_name: "apt_info"
  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: "{{ q('first_found', ['textfile_collector_' + textfile_collector_name + '.yml', 'textfile_collector_generic.yml'] ) | first }}"