State file.managed has defaults and context options for template rendering. Both provide context for template vars.
What is the difference between them?
The core of the Salt State system is the SLS, or SaLt State file. The SLS is a representation of the state in which a system should be in, and is set up to contain this data in a simple format. This is often called configuration management.
A “highstate” is a way for Salt to dynamically determine which Salt Formulas should be applied to a certain minion. To start with you execute a “highstate” like this: salt 'minion01' state.highstate. This command causes the Minion to download and examine a file from the Salt Master called the “top file”.
defaults are the fallback default values that will be passed to the template in case context doesn't have a proper value. If context has a value - it will override default. E.g:
/etc/myconfig.cfg:
- file.managed:
- source: salt://myconfig.tmpl
- template: jinja
- defaults:
foo: bar
- context:
foo: baz
In this case value of foo will always be baz. Generally context is used when you need to have conditional values. E.g.:
/etc/myconfig.cfg:
- file.managed:
- source: salt://myconfig.tmpl
- template: jinja
- defaults:
foo: bar
{% if salt[grains.get]("os") == 'Debian' %}
- context:
foo: baz
{% endif %}
In this case every non-Debian system will end-up having value bar, while Debian will have baz in the template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With