From 232bdca2add4253981b0873188663069f74a0610 Mon Sep 17 00:00:00 2001 From: Colin Wilk Date: Sun, 11 Jun 2023 18:53:04 +0200 Subject: Add ability to specify target path prefix This will decrease the amount of redundant configuration for users by allowing them to specify a general prefix on global / exporter / play level Signed-off-by: Colin Wilk --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index dfc3939..f3d285c 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,9 @@ prometheus_target_exporter_defaults: {} # path: /opt/prometheus/targets.yml # host: '{{ inventory_hostname }}:9100' # blackbox_exporter: - # path: /opt/prometheus/blackbox.yml + # path: /opt/targets/blackbox.yml # host: 'https://{{ hostvars[inventory_hostname].ansible_host }}' + # path_prefix: '' prometheus_target_exporter: [] ``` @@ -71,6 +72,26 @@ prometheus_target_default_exporters: [] prometheus_target_skip_default_exporters: false ``` +As you usually have most target files in one directory you can specify a target +prefix for your target files: + +```yaml +prometheus_target_exporter_target_prefix: '' +``` + +This way you only need to pass `target.yml` instead of `/path/to/target.yml` as +your exporter path. You can additionally define this at the +`prometheus_target_exporter_defaults` and the `prometheus_target_exporter` level +using the `path_prefix` variable: + +```yaml +prometheus_target_exporter_defaults: + blackbox_exporter: + path: /opt/targets/blackbox.yml + host: 'https://{{ hostvars[inventory_hostname].ansible_host }}' + path_prefix: '' # Disables configured prefix +``` + This role offers a few strategies that you can use to deploy your targets. The strategy decides how exactly targets are added to the targets file and more importantly how to handle existing configuration. @@ -164,6 +185,32 @@ Simple example - id: node_exporter ``` +Using Target prefix + +```yaml +- name: Deploy node exporter with target prefix + hosts: myhost + + vars: # General configuration. Can be set in group_vars + prometheus_target_host: prometheus + prometheus_target_exporter_target_prefix: /opt/prometheus/targets/ + prometheus_target_exporter_defaults: + node_exporter: + path: node.yml + host: '{{ inventory_hostname }}:9100' + blackbox_exporter: # Another exporter with different prefix + path: target.yml + host: '{{ inventory_hostname }}' + path_prefix: /opt/prefix/ + + roles: + - role: kliwniloc.prometheus_target + prometheus_target_exporter: + - id: node_exporter # -> /opt/prometheus/targets/node.yml + - { id: node_exporter, path: /target.yml, path_prefix: '' } # -> /target.yml + - { id: blackbox_exporter, path: blackbox.yml } # -> /opt/prefix/blackbox.yml +``` + Using Handlers ```yaml -- cgit v1.2.3