1
0
Fork 0
mirror of synced 2024-11-22 08:55:35 -05:00

Manage grains using support metadata

Change-Id: I8ab61330338213b474ec372e911667f7255eafbd
This commit is contained in:
Filip Pytloun 2017-04-29 09:37:32 +02:00
parent 32bf75e7c8
commit 44657188cf
5 changed files with 21 additions and 58 deletions

View file

@ -1,52 +1,11 @@
{%- from "grafana/map.jinja" import collector with context %} {%- from "grafana/map.jinja" import collector with context %}
{%- if collector.get('enabled', False) %} {%- if collector.get('enabled', False) %}
grafana_grains_dir: # This state is only used to map grains.collector pillar. Grains are now
file.directory: # managed from salt.minion.grains so we will just include it in case it's
- name: /etc/salt/grains.d # executed explicitly
- mode: 700
- makedirs: true
- user: root
{%- set service_grains = {} %} include:
- salt.minion.grains
{# Loading the other service support metadata for localhost #}
{%- for service_name, service in pillar.iteritems() %}
{%- if service.get('_support', {}).get('grafana', {}).get('enabled', False) %}
{%- macro load_grains_file(grains_fragment_file) %}{% include grains_fragment_file ignore missing %}{% endmacro %}
{%- set grains_fragment_file = service_name+'/meta/grafana.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) %}
{%- endif %}
{%- endfor %}
grafana_grain:
file.managed:
- name: /etc/salt/grains.d/grafana
- source: salt://grafana/files/grafana.grain
- template: jinja
- user: root
- mode: 600
- defaults:
service_grains:
grafana: {{ service_grains|yaml }}
- require:
- file: grafana_grains_dir
grafana_grains_file:
cmd.wait:
- name: cat /etc/salt/grains.d/* > /etc/salt/grains
- watch:
- file: grafana_grain
grafana_grains_publish:
module.run:
- name: mine.update
- watch:
- cmd: grafana_grains_file
{%- endif %} {%- endif %}

View file

@ -1 +0,0 @@
{{ service_grains|yaml(False) }}

View file

@ -7,7 +7,4 @@ include:
{%- if pillar.grafana.client is defined %} {%- if pillar.grafana.client is defined %}
- grafana.client - grafana.client
{%- endif %} {%- endif %}
{%- if pillar.grafana.collector is defined %}
- grafana.collector
{%- endif %}
{%- endif %} {%- endif %}

View file

@ -54,11 +54,3 @@ Debian:
{%- endload %} {%- endload %}
{%- set client = salt['grains.filter_by'](client_defaults, merge=salt['pillar.get']('grafana:client')) %} {%- set client = salt['grains.filter_by'](client_defaults, merge=salt['pillar.get']('grafana:client')) %}
{%- load_yaml as collector_defaults %}
default:
storage:
engine: salt-mine
{%- endload %}
{%- set collector = salt['grains.filter_by'](collector_defaults, merge=salt['pillar.get']('grafana:collector')) %}

16
grafana/meta/salt.yml Normal file
View file

@ -0,0 +1,16 @@
grain:
{%- if pillar.grafana.collector is defined %}
{%- if collector.get('enabled', False) %}
{%- set service_grains = {} %}
{%- for service_name, service in pillar.iteritems() %}
{%- if service.get('_support', {}).get('grafana', {}).get('enabled', False) %}
{%- macro load_grains_file(grains_fragment_file) %}{% include grains_fragment_file ignore missing %}{% endmacro %}
{%- set grains_fragment_file = service_name+'/meta/grafana.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) %}
{%- endif %}
{%- endfor %}
grafana:
{{ service_grains|yaml(False)|indent(4) }}
{%- endif %}
{%- endif %}