Jinja and regex problem

115 views
Skip to first unread message

Rainer

unread,
Dec 20, 2019, 3:07:29 AM12/20/19
to Salt-users
Hello,

I want to match a regex against a grain in a Jinja if like in this code that is part of a state file:

{% if grains.osfinger | regex_match('.*SLES-12.*', ignorecase=True)  %}
(%   set hostmode='server' %}
{% else %}
{%   set hostmode='client' %}
{% endif %}
{%- do salt.log.error(grains.osfinger) -%}
{%- do salt.log.error(hostmode) -%}


# salt-call grains.get osfinger; salt-call state.apply statefile
local:
    SLES-12
[ERROR   ] SLES-12
[ERROR   ] client

The result I would have expected here would be a value of server for the variable hostmode becaus
grains.osfinger is "SLES-12" and so the given regex  should match but it doesn't.

What am I doing wrong here (salt-2019.2.0-46.76.1.x86_64) ?

Thanks
Rainer
Reply all
Reply to author
Forward
0 new messages