Skip to content

Instantly share code, notes, and snippets.

@wtip
Created December 15, 2016 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtip/e3a0851b27a96f311045a3dbffc46716 to your computer and use it in GitHub Desktop.
Save wtip/e3a0851b27a96f311045a3dbffc46716 to your computer and use it in GitHub Desktop.
Ansible template that uses ansible inventory data to generate file based service discovery for prometheus to scrape
---
# Uses ansible inventory to generate file based service discovery for prometheus to scrap
{# Loop over all groups except some #}
{% for group in groups if not group in ['all', 'ungrouped', prometheus_node_exporter_group] %}
{# Loop through hosts in group, if host is part of the prom-exports group, print hostname and port #}
- targets: [{% for host in groups[group] %}{% if prometheus_node_exporter_group in hostvars[host].group_names %}'{{ host }}:{{ prometheus_node_exporter_port }}', {% endif %}{% endfor %}]
labels:
job: '{{ group }}'
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment