{% set devices = query("netbox.netbox.nb_lookup", "devices", api_filter="{{ item.nb_filter }}", raw_data=true) | selectattr("primary_ip") | map(attribute="name") | map("extract", hostvars) -%} scrape_configs: - job_name: "{{ item.name }}" relabel_configs: - source_labels: [__address__] regex: '([^.]+).*' target_label: name replacement: ${1} static_configs: - targets: {% for address in devices | selectattr("dns_name", "defined") | map(attribute="dns_name") | reject("none") | sort | unique %} - "{{ address }}:9100" {% endfor %}