Has anyone ever written and registered a custom Jinja filter in Salt?
There is a built-in Jinja filter, "replace", that does a simple string replacement:
{{ grains['full_host_name']|replace('.com', '.bla') }}
This would replace "
somehost.com" with "
somehost.bla". What I need, though, is a filter that does
regular expression replacement, as in the following hypothetical example to extract the host component from a FQDN:
- after: "{{ grains['full_host_name']|re_replace('\..*$', '') }}"
Writing the filter method itself is trivial using the "re" package. But I've been banging my head against the wall all day trying to register the filter in Salt. The Jinja docs say that I just need to "register it on the template environment by updating the filters dict on the environment" (
http://jinja.pocoo.org/docs/api/#custom-filters) but I couldn't find out how that translates to how salt uses Jinja in the renderer.
Any pointers would be greatly appreciated. :)
Bernd.