我刚安装了一个香草SaltStack主人和小兵。我正在尝试按照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正确显示输出文件中的空白行。
我希望它看起来有点链接:
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根本没有阅读支柱文件。我做错了什么?
答案 0 :(得分:1)
看起来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
使用top.sls
文件支持数据needs to be applied to minions。我的猜测是你没有将你的支柱数据应用到你的小兵身上。 /srv/pillar/top.sls
是否包含类似的内容?
base:
'minionid':
- php