diff options
| author | Colin Wilk <colin.wilk@tum.de> | 2023-06-15 22:40:27 +0200 |
|---|---|---|
| committer | Colin Wilk <colin.wilk@tum.de> | 2023-06-15 22:52:07 +0200 |
| commit | 579b168b2c93daee67ede17ee3289da1678b3833 (patch) | |
| tree | 697ffd94cdcb0f8a8e3510947c7aafade4df8594 /tasks | |
| parent | cb503dc08f1c1b447d869d48e57069156574a1fd (diff) | |
| download | ansible-role-prometheus-target-579b168b2c93daee67ede17ee3289da1678b3833.tar.gz ansible-role-prometheus-target-579b168b2c93daee67ede17ee3289da1678b3833.zip | |
Add ability to use exporter without id propertyv1.1.0
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 <colin.wilk@tum.de>
Diffstat (limited to 'tasks')
| -rw-r--r-- | tasks/lineinfile.yml | 14 |
1 files changed, 9 insertions, 5 deletions
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 |