aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/molecule
diff options
context:
space:
mode:
authorColin Wilk <colin@wilk.cx>2026-08-11 00:54:41 +0200
committerColin Wilk <colin@wilk.cx>2026-08-11 00:54:41 +0200
commitc267536ecfbcf37e68226ade2ed29c3b1f356a98 (patch)
tree0fb9728b0095dd34b873fa6c137b75c60734940d /molecule
parentc33948c219032977779a7ef6d82c16e84f37b81a (diff)
downloadansible-role-prometheus-target-c267536ecfbcf37e68226ade2ed29c3b1f356a98.tar.gz
ansible-role-prometheus-target-c267536ecfbcf37e68226ade2ed29c3b1f356a98.zip
Add `state` option for removing exporters
Diffstat (limited to 'molecule')
-rw-r--r--molecule/default/converge.yml48
-rw-r--r--molecule/default/molecule.yml7
-rw-r--r--molecule/default/tests/test_lineinfile_strategy.py7
-rw-r--r--molecule/default/tests/test_yaml_strategy.py6
4 files changed, 62 insertions, 6 deletions
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml
index 59d63bc..8e0b5c9 100644
--- a/molecule/default/converge.yml
+++ b/molecule/default/converge.yml
@@ -743,3 +743,51 @@
prometheus_target_exporter:
- path: /opt/handler_disabled.yml
host: application
+
+################################################################################
+################################################################################
+- name: Remove lineinfile exporters
+ hosts: application_remove
+ vars:
+ prometheus_target_host: prometheus
+ prometheus_target_strategy_lineinfile_prefix: " - "
+ prometheus_target_exporter_defaults:
+ remove_shared:
+ path: /opt/lineinfile_state_removal.yml
+ host: remove:9100
+ state: absent
+
+ roles:
+ - role: kliwniloc.prometheus_target
+ prometheus_target_exporter:
+ - id: remove_shared
+ - path: /opt/lineinfile_state_removal.yml
+ host: remove:9200
+ state: absent
+ - path: /opt/lineinfile_state_missing.yml
+ host: missing:9100
+ state: absent
+
+################################################################################
+################################################################################
+- name: Remove YAML exporters
+ hosts: application_remove
+ vars:
+ prometheus_target_host: prometheus
+ prometheus_target_strategy: yaml
+ prometheus_target_exporter_defaults:
+ remove_shared:
+ path: /opt/yaml_state_removal.yml
+ host: remove:9100
+ state: absent
+
+ roles:
+ - role: kliwniloc.prometheus_target
+ prometheus_target_exporter:
+ - id: remove_shared
+ - path: /opt/yaml_state_removal.yml
+ host: remove:9200
+ state: absent
+ - path: /opt/yaml_state_missing.yml
+ host: missing:9100
+ state: absent
diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml
index 04d4391..bdc5df7 100644
--- a/molecule/default/molecule.yml
+++ b/molecule/default/molecule.yml
@@ -43,6 +43,13 @@ platforms:
- name: molecule-container-net
groups: [application_group]
+ - name: application_remove
+ image: ${MOLECULE_DISTRO:-debian:12}
+ dockerfile: Dockerfile.j2
+ pre_build_image: false
+ networks:
+ - name: molecule-container-net
+
- name: prometheus
image: ${MOLECULE_DISTRO:-debian:12}
dockerfile: Dockerfile.j2
diff --git a/molecule/default/tests/test_lineinfile_strategy.py b/molecule/default/tests/test_lineinfile_strategy.py
index 770459e..d7f9738 100644
--- a/molecule/default/tests/test_lineinfile_strategy.py
+++ b/molecule/default/tests/test_lineinfile_strategy.py
@@ -122,11 +122,12 @@ def test_disabled_handlers_do_not_run(host):
assert not host.file("/tmp/disabled-shell-handler").exists
-def test_future_lineinfile_removal_fixture_is_untouched(host):
+def test_lineinfile_absent_removes_exporters(host):
assert read_yaml_file(host, "/opt/lineinfile_state_removal.yml") == [
{
"labels": {"job": "shared"},
- "targets": ["keep:9100", "remove:9100"],
+ "targets": ["keep:9100"],
},
- {"labels": {"job": "remove_last"}, "targets": ["remove:9200"]},
+ {"labels": {"job": "remove_last"}, "targets": None},
]
+ assert not host.file("/opt/lineinfile_state_missing.yml").exists
diff --git a/molecule/default/tests/test_yaml_strategy.py b/molecule/default/tests/test_yaml_strategy.py
index c3d0dd9..7f9b6ed 100644
--- a/molecule/default/tests/test_yaml_strategy.py
+++ b/molecule/default/tests/test_yaml_strategy.py
@@ -197,11 +197,11 @@ def test_yaml_skip_default_exporters(host):
assert target.content_string == ""
-def test_future_yaml_removal_fixture_is_untouched(host):
+def test_yaml_absent_removes_exporters_and_empty_groups(host):
assert read_yaml_file(host, "/opt/yaml_state_removal.yml") == [
{
"labels": {"job": "shared"},
- "targets": ["keep:9100", "remove:9100"],
+ "targets": ["keep:9100"],
},
- {"labels": {"job": "remove_last"}, "targets": ["remove:9200"]},
]
+ assert not host.file("/opt/yaml_state_missing.yml").exists