I've just installed a vanilla SaltStack master and minions. I'm trying to follow the instructions on https://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html to create a very basic PHP state.
/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) }}
The output file looks like this:
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
I've added extra lines so that Stack Overflow will display the blank lines in the output file correctly.
I would expect it to look something link this:
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
It appears that Salt isn't reading the pillar file at all. What have I done wrong?
It looks like php_ini_settings: {{ salt.pillar.get('php_ini', {}) | json() }}
does not add any data to the context of your jinja template salt://php.ini.tmpl
.
To debug check if the pillar data is available use the 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
Pillar data needs to be applied to minions like states using a top.sls
file. My guess is that you did not apply your pillar data to your minion. Does /srv/pillar/top.sls
includes somthing like that?
base:
'minionid':
- php