浏览代码

Manage grains using support metadata

Change-Id: I1e1269268a81d8cd01b5fe9328f63e8bf85e941b
pull/41/head
Filip Pytloun 7 年前
父节点
当前提交
70798fd4df
共有 2 个文件被更改,包括 39 次插入8 次删除
  1. +6
    -0
      salt/map.jinja
  2. +33
    -8
      salt/minion/grains.sls

+ 6
- 0
salt/map.jinja 查看文件

@@ -89,11 +89,15 @@ default:
Arch:
pkgs:
- salt-zmq
grains_validity_pkgs:
- python-yaml
Debian:
pkgs:
- salt-minion
- python-m2crypto
- python-psutil
grains_validity_pkgs:
- python-yaml
Gentoo:
pkgs:
- app-admin/salt
@@ -105,6 +109,8 @@ RedHat:
- salt-minion
- python-m2ext
- python-psutil
grains_validity_pkgs:
- PyYaml
{%- endload %}

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

+ 33
- 8
salt/minion/grains.sls 查看文件

@@ -22,23 +22,48 @@ salt_minion_grains_files:
- require:
- 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:
cmd.run:
cmd.wait:
- name: cat /etc/salt/grains.d/* > /etc/salt/grains
- require:
- file: salt_minion_grains_files

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

{%- endif %}

{%- endif %}

正在加载...
取消
保存