summaryrefslogtreecommitdiff
path: root/roles
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2021-05-30 23:24:32 +0200
committerChristian Pointner <equinox@spreadspace.org>2021-06-20 01:44:16 +0200
commitacfdc3ae8545177547fa75510cb9e56e0b909156 (patch)
treed8bbb422a0d4fe733b0f8895ca7128555ef0f089 /roles
parentprometheus: initial simple server role (diff)
prometheus basic exporter base role
Diffstat (limited to 'roles')
-rw-r--r--roles/monitoring/prometheus/exporter/base/defaults/main.yml2
-rw-r--r--roles/monitoring/prometheus/exporter/base/handlers/main.yml5
-rw-r--r--roles/monitoring/prometheus/exporter/base/tasks/main.yml37
-rw-r--r--roles/monitoring/prometheus/exporter/base/templates/service.j231
4 files changed, 68 insertions, 7 deletions
diff --git a/roles/monitoring/prometheus/exporter/base/defaults/main.yml b/roles/monitoring/prometheus/exporter/base/defaults/main.yml
index 5f8ce103..963763a5 100644
--- a/roles/monitoring/prometheus/exporter/base/defaults/main.yml
+++ b/roles/monitoring/prometheus/exporter/base/defaults/main.yml
@@ -1,2 +1,2 @@
---
-prometheus_exporter_port: 9000
+prometheus_exporter_listen: ":9999"
diff --git a/roles/monitoring/prometheus/exporter/base/handlers/main.yml b/roles/monitoring/prometheus/exporter/base/handlers/main.yml
new file mode 100644
index 00000000..ebd760cf
--- /dev/null
+++ b/roles/monitoring/prometheus/exporter/base/handlers/main.yml
@@ -0,0 +1,5 @@
+---
+- name: restart prometheus-exporter-exporter
+ service:
+ name: prometheus-exporter-exporter
+ state: restarted
diff --git a/roles/monitoring/prometheus/exporter/base/tasks/main.yml b/roles/monitoring/prometheus/exporter/base/tasks/main.yml
index 7982f1f9..fab6ff7b 100644
--- a/roles/monitoring/prometheus/exporter/base/tasks/main.yml
+++ b/roles/monitoring/prometheus/exporter/base/tasks/main.yml
@@ -1,15 +1,40 @@
---
-- name: create main configuration directories
- file:
- path: "/etc/prometheus/exporters"
- state: directory
+- name: check if prometheus apt component of spreadspace repo is enabled
+ assert:
+ msg: "please enable the 'prometheus' component of spreadspace repo using 'spreadspace_apt_repo_components'"
+ that:
+ - spreadspace_apt_repo_components is defined
+ - "'prometheus' in spreadspace_apt_repo_components"
- name: install apt packages
apt:
name: prom-exporter-exporter
state: present
+- name: create configuration directories
+ file:
+ path: /etc/prometheus/exporter/enabled
+ state: directory
+
+- name: add user for prometheus-exporter
+ user:
+ name: prometheus-exporter
+ system: yes
+ home: /nonexistent
+ create_home: no
+
## TODO:
-## - systemd service unit
-## - add snippet to exporter-exporter config-dir
## - create certificate/key
+
+- name: generate systemd service unit
+ template:
+ src: service.j2
+ dest: /etc/systemd/system/prometheus-exporter-exporter.service
+ notify: restart prometheus-exporter-exporter
+
+- name: make sure prometheus-exporter-exporter is enabled and started
+ systemd:
+ name: prometheus-exporter-exporter.service
+ daemon_reload: yes
+ state: started
+ enabled: yes
diff --git a/roles/monitoring/prometheus/exporter/base/templates/service.j2 b/roles/monitoring/prometheus/exporter/base/templates/service.j2
new file mode 100644
index 00000000..6069fc79
--- /dev/null
+++ b/roles/monitoring/prometheus/exporter/base/templates/service.j2
@@ -0,0 +1,31 @@
+[Unit]
+Description=Prometheus exporter proxy
+
+[Service]
+Restart=always
+User=prometheus-exporter
+ExecStart=/usr/bin/prometheus-exporter-exporter --config.dirs=/etc/prometheus/exporter/enabled --config.file="" --web.listen-address="{{ prometheus_exporter_listen }}"
+
+# systemd hardening-options
+AmbientCapabilities=
+CapabilityBoundingSet=
+DeviceAllow=/dev/null rw
+DevicePolicy=strict
+LockPersonality=true
+MemoryDenyWriteExecute=true
+NoNewPrivileges=true
+PrivateDevices=true
+PrivateTmp=true
+PrivateUsers=true
+ProtectControlGroups=true
+ProtectHome=true
+ProtectKernelModules=true
+ProtectKernelTunables=true
+ProtectSystem=strict
+RemoveIPC=true
+RestrictNamespaces=true
+RestrictRealtime=true
+SystemCallArchitectures=native
+
+[Install]
+WantedBy=multi-user.target