aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/molecule/default
diff options
context:
space:
mode:
authorColin Wilk <colin.wilk@tum.de>2023-06-11 18:53:04 +0200
committerColin Wilk <colin.wilk@tum.de>2023-06-11 18:53:04 +0200
commit232bdca2add4253981b0873188663069f74a0610 (patch)
treef455d26babf600baad72e5e68d02a7f2730e548c /molecule/default
parent7623b7302f445798fb9d6fe31c1c1eb7085173a4 (diff)
downloadansible-role-prometheus-target-232bdca2add4253981b0873188663069f74a0610.tar.gz
ansible-role-prometheus-target-232bdca2add4253981b0873188663069f74a0610.zip
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 <colin.wilk@tum.de>
Diffstat (limited to 'molecule/default')
-rw-r--r--molecule/default/converge.yml45
-rw-r--r--molecule/default/tests/test_check_prometheus_targets.py21
2 files changed, 65 insertions, 1 deletions
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml
index 8f2b399..e96fb81 100644
--- a/molecule/default/converge.yml
+++ b/molecule/default/converge.yml
@@ -1,4 +1,6 @@
---
+################################################################################
+################################################################################
- name: Simple deploy
hosts: application
pre_tasks:
@@ -37,7 +39,47 @@
- id: blackbox_exporter
path: /opt/simple_target3.yml
+################################################################################
+################################################################################
+- name: Prefix deploy
+ hosts: application
+ pre_tasks:
+ - name: Create targets
+ ansible.builtin.file:
+ path: '{{ item.path }}'
+ state: '{{ item.state }}'
+ modification_time: preserve
+ access_time: preserve
+ mode: '0644'
+ become: true
+ delegate_to: '{{ prometheus_target_host }}'
+ loop:
+ - { state: touch, path: /opt/prefix_target1.yml }
+ - { state: touch, path: /opt/prefix_target2.yml }
+ - { state: directory, path: /opt/prefix}
+ - { state: touch, path: /opt/prefix/prefix_target3.yml }
+
+ vars:
+ prometheus_target_host: prometheus
+ prometheus_target_exporter_target_prefix: /opt/
+ prometheus_target_exporter_defaults:
+ node_exporter:
+ path: prefix_target1.yml
+ host: '{{ inventory_hostname }}'
+ blackbox_exporter:
+ path: prefix_target_not_exist.yml
+ host: '{{ inventory_hostname }}'
+ path_prefix: /opt/prefix/
+ roles:
+ - role: kliwniloc.prometheus_target
+ prometheus_target_exporter:
+ - id: node_exporter
+ - { id: node_exporter, path: /opt/prefix_target2.yml, path_prefix: '' }
+ - { id: blackbox_exporter, path: prefix_target3.yml }
+
+################################################################################
+################################################################################
- name: Deploy with hooks
hosts: application
pre_tasks:
@@ -71,7 +113,8 @@
host: application
path: /opt/hook_target.yml
-
+################################################################################
+################################################################################
- name: Deploy with lineinfile
hosts: application
pre_tasks:
diff --git a/molecule/default/tests/test_check_prometheus_targets.py b/molecule/default/tests/test_check_prometheus_targets.py
index 2a45661..9ce1056 100644
--- a/molecule/default/tests/test_check_prometheus_targets.py
+++ b/molecule/default/tests/test_check_prometheus_targets.py
@@ -23,6 +23,27 @@ def test_check_hosts_added_simple(host):
assert t3.content_string == \
' - application_AA\n'
+"""
+Test prefix functionality
+"""
+def test_check_hosts_added_prefix(host):
+ t1 = host.file('/opt/prefix_target1.yml')
+ t2 = host.file('/opt/prefix_target2.yml')
+ t3 = host.file('/opt/prefix/prefix_target3.yml')
+
+ assert t1.exists
+ assert t2.exists
+ assert t3.exists
+
+ assert t1.content_string == \
+ ' - application\n'
+
+
+ assert t2.content_string == \
+ ' - application\n'
+
+ assert t3.content_string == \
+ ' - application\n'
"""
Test hook functionality