Manage grains using support metadata
Change-Id: I8ab61330338213b474ec372e911667f7255eafbd
This commit is contained in:
parent
32bf75e7c8
commit
44657188cf
5 changed files with 21 additions and 58 deletions
|
@ -1,52 +1,11 @@
|
|||
{%- from "grafana/map.jinja" import collector with context %}
|
||||
{%- if collector.get('enabled', False) %}
|
||||
|
||||
grafana_grains_dir:
|
||||
file.directory:
|
||||
- name: /etc/salt/grains.d
|
||||
- mode: 700
|
||||
- makedirs: true
|
||||
- user: root
|
||||
# This state is only used to map grains.collector pillar. Grains are now
|
||||
# managed from salt.minion.grains so we will just include it in case it's
|
||||
# executed explicitly
|
||||
|
||||
{%- set service_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
|
||||
include:
|
||||
- salt.minion.grains
|
||||
|
||||
{%- endif %}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{{ service_grains|yaml(False) }}
|
|
@ -7,7 +7,4 @@ include:
|
|||
{%- if pillar.grafana.client is defined %}
|
||||
- grafana.client
|
||||
{%- endif %}
|
||||
{%- if pillar.grafana.collector is defined %}
|
||||
- grafana.collector
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
|
|
|
@ -54,11 +54,3 @@ Debian:
|
|||
{%- endload %}
|
||||
|
||||
{%- 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
16
grafana/meta/salt.yml
Normal 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 %}
|
Loading…
Reference in a new issue