Merge pull request #60 from SwannCroiset/fix-grains
Fix the heka grains for the aggregator/remote_collector
diff --git a/heka/_service.sls b/heka/_service.sls
index 5749b2d..b990341 100644
--- a/heka/_service.sls
+++ b/heka/_service.sls
@@ -119,8 +119,6 @@
{# Loading the other services' support metadata for local roles #}
-{%- if service_name in ['log_collector', 'metric_collector'] %}
-
{%- for service_name, service in pillar.iteritems() %}
{%- if service.get('_support', {}).get('heka', {}).get('enabled', False) %}
@@ -131,23 +129,19 @@
{%- endif %}
{%- endfor %}
-{%- endif %}
-
-{%- if service_name in ['remote_collector', 'aggregator'] %}
-
-{# Load the support metadata from heka/meta/heka.yml #}
-
-{%- set grains_fragment_file = 'heka/meta/heka.yml' %}
-{%- set grains_yaml = load_grains_file(grains_fragment_file)|load_yaml %}
-{%- set service_grains = salt['grains.filter_by']({'default': service_grains}, merge=grains_yaml) %}
+{%- if service_name in ('remote_collector', 'aggregator') %}
{# Load the other services' support metadata from salt-mine #}
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
{%- if node_grains.heka is defined %}
-{%- set service_grains = salt['grains.filter_by']({'default': service_grains}, merge=node_grains.heka) %}
-{%- endif %}
+{% for service, data in node_grains.heka.items() %}
+ {%- if service in ('remote_collector', 'aggregator') %}
+ {%- do salt['grains.filter_by']({'default': service_grains[service]}, merge=data) %}
+ {%- endif %}
+{% endfor %}
+{% endif %}
{%- endfor %}
{%- endif %}