`{{ source }}` in formulas

27 views
Skip to first unread message

Florian Ermisch

unread,
Jun 16, 2017, 7:10:37 PM6/16/17
to [salt-users]
Hi everyone,

I like the idea of having the URLs for
the templates used included in files
managed by Salt formulas (in Jinja
via the usage of `{{ source }}`).
As some people don't like having their
files changed when switching the
saltenv [0] I'd propose using pillar for
both a global switch and a formula
specific override. Something like

salt-formulas:
print_template_url: True
zabbix-formula:
print_template_url: False

With a default of `None` for `pillar.get`
this works (`if (global or local) and local`*)
while being only a bit unwieldy**:

{% set global_src_url = salt ['pillar.get']('salt-formulas:print_template_url', None) -%}
{% set local_src_url = salt ['pillar.get']('zabbix-formula:print_template_url', None) -%}
# This File is Managed by Salt! Don't Touch!
{% if (global_src_url or local_src_url) and local_src_url -%}
# Template used: {{ source }}
{% endif -%}

To spice things up one can even have
different defaults for the calls to
`pillar.get` in different files of a formula
(might be used to add this feature
without having it change the default
behavior of the formula).


Thoughts?


Regards, Florian

PS: The snippets here are not the
ones I've tested this with and may
contain (additional) typos

*) Close to the `AND` of a
true/irrelevant/false three-valued
logic [1] I guess
**) Not more so than `map.jinja` easily
gets, right? ;)

[0]: https://github.com/saltstack-formulas/salt-formula/pull/316
[1]: https://en.m.wikipedia.org/wiki/Three-valued_logic

Seth House

unread,
Jun 19, 2017, 5:47:42 PM6/19/17
to salt users list, Florian Ermisch
Hi, Florian.

This sounds like a good proposal. I vaguely recall a use-case for
having a global formulas namespace from years back but if that ever
made it to a GitHub issue I can't find it now.

The only suggestion I have is to differentiate the namespace a bit
more to avoid potential confusion with individual formula namespaces.
Perhaps something ugly but noticeable like `__formulas?

Florian Ermisch

unread,
Jun 21, 2017, 7:34:08 PM6/21/17
to salt users list
Hi everyone,

I've implemented this (with Seth's
more sensible `__formulas` key) for
the openssh-formula:

https://github.com/saltstack-formulas/openssh-formula/pull/97

Let's see how long it will take for me
to add this to other formulas ; )

Regards, Florian
Reply all
Reply to author
Forward
0 new messages