Skip to content

Commit

Permalink
prometheus: fix default() with correct static value
Browse files Browse the repository at this point in the history
var[] comes from the first host this task started to run
not from the current host in the loop

without this change all hosts using defaults for
tor_ports and tor_prometheus_scrape_port
would use the values from the host this task started to run
instead of the actual defaults
  • Loading branch information
nusenu committed Jul 19, 2022
1 parent b4f2ad2 commit edb4936
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions templates/prometheus-scrape-configs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% for host in ansible_play_hosts %}
{% set c = namespace(i=0) %}
{% for ip in hostvars[host]['tor_ips'] %}
{% for port in hostvars[host]['tor_ports']|default(vars['tor_ports']) %}
{% for port in hostvars[host]['tor_ports']|default([{ 'orport': 9000, 'dirport': 9001}, { 'orport': 9100, 'dirport': 9101}]) %}
- job_name: '{{host}}-tor-{{c.i}}'
metrics_path: '/{{ lookup('password', '~/.tor/prometheus/metrics_path/' + host + ' length=10 chars=ascii_lowercase') }}/{{c.i}}'
scheme: 'https'
Expand All @@ -11,7 +11,7 @@
password: "{{ lookup('password', tor_prometheus_scrape_password_folder + host ) }}"
static_configs:
- targets:
- "{{hostvars[host].ansible_fqdn}}:{{ hostvars[host]['tor_prometheus_scrape_port'] | default(vars['tor_prometheus_scrape_port']) }}"
- "{{hostvars[host].ansible_fqdn}}:{{ hostvars[host]['tor_prometheus_scrape_port'] | default(443) }}"
labels:
id: "{{ ip.ipv4 }}_{{ port.orport }}"
{% set c.i = c.i + 1 %}
Expand Down

0 comments on commit edb4936

Please sign in to comment.