From 579b168b2c93daee67ede17ee3289da1678b3833 Mon Sep 17 00:00:00 2001 From: Colin Wilk Date: Thu, 15 Jun 2023 22:40:27 +0200 Subject: Add ability to use exporter without id property The id property of the exporter is used for checking the default values specified in `prometheus_target_exporter_defaults` variable. However when both the `host` and the `path` fields are specified manually in the `prometheus_target_exporter` list this id is never looked up. The way the templating was handled however, still resulted in an error when leaving out the id field. The templating code was now rewritten to allow for the following exporter configuraion to run: prometheus_target_exporter: - { host: exporter_without_id, path: /opt/simple_target4.yml } Signed-off-by: Colin Wilk --- tasks/lineinfile.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tasks/lineinfile.yml') diff --git a/tasks/lineinfile.yml b/tasks/lineinfile.yml index d7f0793..0367be9 100644 --- a/tasks/lineinfile.yml +++ b/tasks/lineinfile.yml @@ -1,12 +1,16 @@ --- - name: Make sure targets are deployed ansible.builtin.lineinfile: - path: '{{ (item.path_prefix - | default(prometheus_target_exporter_defaults[item.id].path_prefix) - | default(prometheus_target_exporter_target_prefix)) ~ - item.path | default(prometheus_target_exporter_defaults[item.id].path) }}' + path: '{{ ( + item.path_prefix if item.path_prefix is defined else + (prometheus_target_exporter_defaults[item.id].path_prefix + | default(prometheus_target_exporter_target_prefix)) + if item.id is defined) + ~ + (item.path if item.path is defined + else prometheus_target_exporter_defaults[item.id].path if item.id is defined) | mandatory }}' line: '{{ prometheus_target_strategy_lineinfile_prefix ~ - (item.host | default(prometheus_target_exporter_defaults[item.id].host)) ~ + (item.host if item.host is defined else prometheus_target_exporter_defaults[item.id].host) | mandatory ~ prometheus_target_strategy_lineinfile_suffix }}' state: present become: true -- cgit v1.2.3