I would like to have less conditions in my saltstack sls files.
Up to now it looks like this:
foo_package:
pkg.installed:
- pkgs:
{% if grains.os_family == 'Debian' %}
- foo_BAR
{% else %}
- foo-bar
{% endif %}
I would like to have it like this:
foo_package:
pkg.installed:
- pkgs:
- {{ foo_BAR | normalize_package_name }}
How to implement normalize_package_name
?
As soon as I can use Python I can help myself and implement this very easily: Underscores should get replaced with -
and upper case characters should get lower case.
I know that I could do it in Jinja like this:
- {{ foo_BAR | replace... | replace .. }}
But this gets used several times, that's why I would like to have a custom filter.
.... some days later: Maybe it is better to write a custom state (mypkg.installed
) and call pkg.installed
after normalizing the package names. See salt docs: https://docs.saltstack.com/en/latest/ref/states/writing.html#cross-calling-state-modules