May be I'm blinded... How to check hostname of "contains or like"

211 views
Skip to first unread message

Tom K.

unread,
May 2, 2016, 7:30:21 AM5/2/16
to Salt-users
Hi,

I searching for a way to check grains['hostname'] with a like comparator by *-wildcard

{% if grains['host'] == 'vm-www-server-101' %}
apache2:
    pkg:
        - installed
{% endif %}


Works. But I want something like


{% if grains['host'] like|contains '*-www-server-*' %}
apache2:
    pkg:
        - installed
{% endif %}


I think it's so easy that I've lost it during reading the how to's..


-- Tom

Christian Joergensen

unread,
May 2, 2016, 9:01:18 AM5/2/16
to Salt-users
Hello,

Use the Jinja 'in' operator:

{% if "-www-server-" in grains['host'] %}

Cheers,

Christian

Tom K.

unread,
May 2, 2016, 9:21:33 AM5/2/16
to Salt-users
Hi Christian,

thanks a lot!! It works!

-- Tom
Reply all
Reply to author
Forward
0 new messages