I'm playing with saltstack but I'm stuck in two questions.
I'm trying to create a formula like the sysctl formula to my servers for testing; I want to use a defaults.yaml file where put all the default values if there is no data configured in the pillars.
The defaults.yaml file looks like:
sysctl:
params:
-
name: net.ipv4_forward
value: 0
-
name: kernel.sysrq
value: 0
The map.jinja is:
{% import_yaml 'sysctl/defaults.yaml' as defaults_settings %}
{% set sysctl_settings = salt['pillar.get'](
'sysctl',
default=defaults_settings.sysctl,
merge=defaults_settings.sysctl
)
%}
The pillar for a server:
{% if grains['fqdn'] == 'server1' %}
sysctl:
params:
-
name: net.ipv4_forward
value: 1
{% endif %}
And the state where apply the config:
{% from "sysctl/map.jinja" import sysctl_settings with context %}
{% for param in sysctl_settings.get('params', {}) %}
sysctl.present:
- value: {{ param.value }}
{% endfor %}
The first problem is that when I apply the state to the server1 it only applies the data configured in the pillar, it doesn't take the data in the defaults.yaml (in that case the kernel.sysrq option from yaml only because the net.ipv4_forward should be use the pillar one).
How can I achieve this?
The second problem is that if I remove the server from the pillar, because I want to apply only the default values, and apply the state; salt shows the following error:
Rendering SLS 'base:sysctl.param' failed: Jinja variable 'dict object' has no attribute 'sysctl'
I don't know which is the proper way to deal with this.
Could someone give me an idea?
The master version is 2014.7.0 and minion 2014.7.5 both running on ubuntu server 12.04.
Best regards and thanks,
David