I'm trying to write a Jinja macro that will allow me to template a
file configuration and I'm hoping someone kind provide me with some advice.
The configuration file itself requires certain settings to appear in order. I would like to be able to pass a dict as an optional variable to my macro so that I can override the default settings in the configuration file as well as pass non-default settings.
For example, my default settings might look like this:
{% set default = { 'default_setting': 'default_value', 'another_default_setting': 'another_default_value', } %}
And my new settings:
{% set new = { 'default_setting': 'new_value', 'new_setting': 'another_new_value', } %}
Then in my template:
{% set settings = salt['slsutil.merge'](default, new, 'overwrite') %}
{% for setting, value in settings.items() %}
{{ setting }} = {{ value }};
{% endfor %}
Which should output:
default_setting = new_value;
another_default_setting = another_default_value;
new_setting = another_new_value;
Is this possible to do or am I heading in the wrong direction?
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/3cd747ce-083f-41eb-8fd9-e6078231884f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Have you looked at the salt-formulas github repository. Many examples there of merging default values and custom values based on OS or pillar.HTH
On 10 April 2018 at 04:05, Nicholas Wylie <now...@gmail.com> wrote:
I'm trying to write a Jinja macro that will allow me to template a file configuration and I'm hoping someone kind provide me with some advice.
The configuration file itself requires certain settings to appear in order. I would like to be able to pass a dict as an optional variable to my macro so that I can override the default settings in the configuration file as well as pass non-default settings.
For example, my default settings might look like this:
{% set default = { 'default_setting': 'default_value', 'another_default_setting': 'another_default_value', } %}And my new settings:
{% set new = { 'default_setting': 'new_value', 'new_setting': 'another_new_value', } %}Then in my template:
{% set settings = salt['slsutil.merge'](default, new, 'overwrite') %}
{% for setting, value in settings.items() %}
{{ setting }} = {{ value }};
{% endfor %}
Which should output:
default_setting = new_value;
another_default_setting = another_default_value;
new_setting = another_new_value;
Is this possible to do or am I heading in the wrong direction?
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/f3cdb7bb-568b-455b-90c9-efa1c5b8d9d5%40googlegroups.com.