Jinja Wildcards in States

3,516 views
Skip to first unread message

Robert Hernandez

unread,
Sep 25, 2012, 8:08:51 PM9/25/12
to salt-...@googlegroups.com
I cant find out how to do wildcards when comparing strings in Jinja.  Im trying to do the following comparison with the grains['osrelease'] == '6*' but it does not seems to match.  Here is my state file:

{% if grains['os_family'] == 'RedHat' %}
{% if grains['osrelease'] == '6*'* %}
yum-plugin-priorities:
  pkg:
    - installed

rpmforge_repos:
  cmd.run:
    - unless: rpm -qa | grep -q rpmforge
    - names:
      - rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
    - require:
      - pkg: yum-plugin-priorities
{% endif %}

{% if grains['osrelease'] == '5*' %}
yum-priorities:
  pkg:
    - latest
    - require:
      - pkg: yum
{% endif %}
{% endif %}

 Ive been looking up and down the Jinja docs with no luck.  Any help would be greatly appreciated.

~Rob

Thomas S Hatch

unread,
Sep 25, 2012, 8:13:01 PM9/25/12
to salt-...@googlegroups.com
does .startswith work?
{% if grains['osrelease'].startswith('6') %}

Robert Hernandez

unread,
Sep 25, 2012, 8:25:40 PM9/25/12
to salt-...@googlegroups.com
Yes it does, thanks Tom!  I didn't realize I could just use the built-in python string methods.  

~Rob

Thomas S Hatch

unread,
Sep 26, 2012, 12:40:53 AM9/26/12
to salt-...@googlegroups.com
Anytime :)

Jacob Albretsen

unread,
Sep 27, 2012, 8:44:54 AM9/27/12
to salt-...@googlegroups.com
On Tuesday, September 25, 2012 06:13:01 PM Thomas S Hatch wrote:
> does .startswith work?
> {% if grains['osrelease'].startswith('6') %}

I've been doing it this way:

grains['osrelease'][0] == '6'

Robert Hernandez

unread,
Sep 27, 2012, 1:05:18 PM9/27/12
to salt-...@googlegroups.com
This is another great way to go about getting a match to the string, thanks Jacob!
Reply all
Reply to author
Forward
0 new messages