diff options
| author | Magnus Kühne <73171182+magkue@users.noreply.github.com> | 2026-02-09 17:23:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-09 17:23:57 +0100 |
| commit | 049689c124a274870b5405ff6816beeba7d94a14 (patch) | |
| tree | 583b94ca62c1268bf359d47309ad24823ba9d458 /tasks/process_exporter.yml | |
| parent | 61a0abc5ac4b5d600ee17fef52d7340a9475ac9b (diff) | |
| download | ansible-role-prometheus-target-049689c124a274870b5405ff6816beeba7d94a14.tar.gz ansible-role-prometheus-target-049689c124a274870b5405ff6816beeba7d94a14.zip | |
Add support for YAML strategy
Introduces a new 'yaml' strategy using Ansible's `from_yaml` to read
target files. This allows users to group multiple targets with
distinct label sets (e.g., severity or job) within a single file,
optimizing Prometheus file-based service discovery.
- Refactored task structure into `strategy_*.yml` for consistency.
- Extracted shared exporter variable computation.
- Implemented label merging where exporter labels override defaults.
- Included support for groups and hosts without labels to prevent crashes.
PR: (#1) https://github.com/kliwniloc/ansible-role-prometheus-target/pull/1
Diffstat (limited to 'tasks/process_exporter.yml')
| -rw-r--r-- | tasks/process_exporter.yml | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tasks/process_exporter.yml b/tasks/process_exporter.yml new file mode 100644 index 0000000..2d13b29 --- /dev/null +++ b/tasks/process_exporter.yml @@ -0,0 +1,18 @@ +--- +- name: Set exporter variables + vars: + _defaults: '{{ prometheus_target_exporter_defaults[item.id] | default({}) if item.id is defined else {} }}' + ansible.builtin.set_fact: + _target_path: >- + {{ (item.path_prefix if item.path_prefix is defined else + (_defaults.path_prefix | default(prometheus_target_exporter_target_prefix))) + ~ + (item.path if item.path is defined else _defaults.path) | mandatory }} + _target_host: >- + {{ (item.host if item.host is defined else _defaults.host) | mandatory }} + _target_labels: >- + {{ (_defaults.labels | default({})) | combine(item.labels | default({})) }} + +- name: Execute strategy + ansible.builtin.include_tasks: + file: strategy_{{ prometheus_target_strategy }}.yml |