Browse Source

Manage grains using support metadata

Change-Id: I1e1269268a81d8cd01b5fe9328f63e8bf85e941b
pull/41/head
Filip Pytloun 7 years ago
parent
commit
70798fd4df
2 changed files with 39 additions and 8 deletions
  1. +6
    -0
      salt/map.jinja
  2. +33
    -8
      salt/minion/grains.sls

+ 6
- 0
salt/map.jinja View File

Arch: Arch:
pkgs: pkgs:
- salt-zmq - salt-zmq
grains_validity_pkgs:
- python-yaml
Debian: Debian:
pkgs: pkgs:
- salt-minion - salt-minion
- python-m2crypto - python-m2crypto
- python-psutil - python-psutil
grains_validity_pkgs:
- python-yaml
Gentoo: Gentoo:
pkgs: pkgs:
- app-admin/salt - app-admin/salt
- salt-minion - salt-minion
- python-m2ext - python-m2ext
- python-psutil - python-psutil
grains_validity_pkgs:
- PyYaml
{%- endload %} {%- endload %}


{%- if pillar.salt.minion is defined %} {%- if pillar.salt.minion is defined %}

+ 33
- 8
salt/minion/grains.sls View File

- require: - require:
- file: salt_minion_grains_dir - file: salt_minion_grains_dir


{%- set new_grains = salt['cmd.run']('cat /etc/salt/grains.d/*') %}
{%- set old_grains = salt['cmd.run']('cat /etc/salt/grains') %}
salt_minion_grains_pkg_validity_check:
pkg.installed:
- pkgs: {{ minion.grains_validity_pkgs }}


{%- if new_grains != old_grains %}
{%- for service_name, service in pillar.items() %}
{%- set support_fragment_file = service_name+'/meta/salt.yml' %}
{%- macro load_support_file() %}{% include support_fragment_file ignore missing %}{% endmacro %}
{%- set support_yaml = load_support_file()|load_yaml %}

{%- if support_yaml %}
{%- for name, grain in support_yaml.get('grain', {}).iteritems() %}
salt_minion_grain_{{ service_name }}_{{ name }}:
file.managed:
- name: /etc/salt/grains.d/{{ name }}
- contents: |
{{ grain|yaml(False)|indent(8) }}
- require:
- file: salt_minion_grains_dir

salt_minion_grain_{{ service_name }}_{{ name }}_validity_check:
cmd.wait:
- name: python -c "import yaml; stream = file('/etc/salt/grains.d/{{ name }}', 'r'); yaml.load(stream); stream.close()"
- require:
- pkg: salt_minion_grains_pkg_validity_check
- watch:
- file: salt_minion_grain_{{ service_name }}_{{ name }}
- watch_in:
- cmd: salt_minion_grains_file
{%- endfor %}
{%- endif %}
{%- endfor %}


salt_minion_grains_file: salt_minion_grains_file:
cmd.run:
cmd.wait:
- name: cat /etc/salt/grains.d/* > /etc/salt/grains - name: cat /etc/salt/grains.d/* > /etc/salt/grains
- require: - require:
- file: salt_minion_grains_files - file: salt_minion_grains_files


salt_minion_grains_publish: salt_minion_grains_publish:
module.run:
module.wait:
- name: mine.update - name: mine.update
- require:
- watch:
- cmd: salt_minion_grains_file - cmd: salt_minion_grains_file


{%- endif %} {%- endif %}

{%- endif %}

Loading…
Cancel
Save