`{{ source }}` in formulas

Visto 27 veces
Saltar al primer mensaje no leído

Florian Ermisch

no leída,
16 jun 2017, 19:10:3716/6/17
a [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

no leída,
19 jun 2017, 17:47:4219/6/17
a 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

no leída,
21 jun 2017, 19:34:0821/6/17
a 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
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos