从 SaltStack 支柱文件中读取

Read from SaltStack pillar files

我刚刚安装了普通的 SaltStack master 和 minions。我正在尝试按照 https://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html 上的说明创建一个非常基本的 PHP 状态。

/srv/salt/php.sls:

php_ini:
  file.managed:
    - name: /etc/php.ini
    - source: salt://php.ini.tmpl
    - template: jinja
    - context:
        php_ini_settings: {{ salt.pillar.get('php_ini', {}) | json() }}

/srv/pillar/php.sls:

php_ini:
  PHP:
    engine: 'On'
    short_open_tag: 'Off'
    error_reporting: 'E_ALL & ~E_DEPRECATED & ~E_STRICT'

/srv/salt/php.ini.tmpl:

{% macro php_ini_serializer(data) %}
{% for section_name, name_val_pairs in data.items() %}
[{{ section_name }}]
{% for name, val in name_val_pairs.items() -%}
{{ name }} = "{{ val }}"
{% endfor %}
{% endfor %}
{% endmacro %}

; File managed by Salt at <{{ source }}>.
; Your changes will be overwritten.

{{ php_ini_serializer(php_ini_settings) }}

输出文件如下所示:

VVV File starts on the next line


; File managed by Salt at <salt://php.ini.tmpl>.
; Your changes will be overwritten.



^^^ File ends on the previous line

我添加了额外的行,以便 Stack Overflow 能够正确显示输出文件中的空行。

我希望它看起来像 link 这个:

VVV File starts on the next line


; File managed by Salt at <salt://php.ini.tmpl>.
; Your changes will be overwritten.

[PHP]
engine = "On"
short_open_tag = "Off"
error_reporting = "E_ALL & ~E_DEPRECATED & ~E_STRICT"


^^^ File ends on the previous line

似乎 Salt 根本没有读取支柱文件。我做错了什么?

看起来 php_ini_settings: {{ salt.pillar.get('php_ini', {}) | json() }} 没有将任何数据添加到您的 jinja 模板的上下文中 salt://php.ini.tmpl

要调试检查支柱数据是否可用,请使用 pillar module

salt 'minionid' pilar.ls  # to check the existence of keys
salt 'minionid' pilar.items  # to explore whole the pillar data of your minion 

支柱数据 needs to be applied to minions 喜欢使用 top.sls 文件的状态。我的猜测是您没有将支柱数据应用于您的小兵。 /srv/pillar/top.sls 是否包括类似的东西?

base:
  'minionid':
    - php