I want to use multiple if statements in salt but not able to find desired result.

1,693 views
Skip to first unread message

Ajinkya Joshi

unread,
Jan 30, 2015, 2:03:50 AM1/30/15
to salt-...@googlegroups.com
My init.sls is like this

{% if grains['os'] == 'CentOS' %}

  {% if grains['osrelease'] == [5.5','5.6''5.7','5.8','5.9'] %}
  include:
    - project.packages5
  {% endif %}
  
  {% elif grains['osrelease'] == ['6.0','6.1','6.2','6.3',6.4','6.5'] %}
  include:
    - project.packages6
  {% endif %}

{% endif %}

Also i have tried using for but its not working :::

{% if grains['os'] == 'CentOS' %}

  {% for grains['osrelease'] in '5.5','5.6''5.7','5.8','5.9' %}
  include:
    - project.packages5
  {% endfor %}


{% endif %}


Please guide me to filter OS version and then OSrelease !!!



Dmitry Golubenko

unread,
Jan 30, 2015, 2:40:49 AM1/30/15
to salt-...@googlegroups.com
В Чтв, 29/01/2015 в 23:03 -0800, Ajinkya Joshi пишет:
your staes do not work because you use space indents, this breaks yaml.
remove unnecessary indents at start of lines or
try somthing like this
{% if grains['os'] == 'CentOS' %}
{% if grains['osrelease'].startswith('5') %}
include:
- project.packages5
{% endif %}
{% endif %}

or even simplier:
{% if grains['os'] == 'CentOS' %}
include:
- project.packages{{ grains['osrelease']|truncate('1', true) }}
{% endif %}

>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Salt-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to salt-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



Nicolas REY

unread,
Jan 31, 2015, 5:47:45 AM1/31/15
to salt-...@googlegroups.com
Dmitry Golubenko's idea with the truncate works fine.


About the sls, he have little mistakes:

{% if grains['os'] == 'CentOS' %}

  {#{% if grains['osrelease'] == [5.5','5.6''5.7','5.8','5.9'] %} missing ' and , and prefer in #}
  {% if grains['osrelease'] in ['5.5','5.6','5.7','5.8','5.9'] %}
  include:
    - project.packages5
  {#{% endif %} endif not necessary, we have an else next him #}
  
  {#{% elif grains['osrelease'] == ['6.0','6.1','6.2','6.3',6.4','6.5'] %} missing ' and prefer in #}
  {% elif grains['osrelease'] in ['6.0','6.1','6.2','6.3','6.4','6.5'] %}
  include:
    - project.packages6
  {% endif %}

{% endif %}



Also i have tried using for but its not working :::

{% if grains['os'] == 'CentOS' %}

  {% for grains['osrelease'] in '5.5','5.6''5.7','5.8','5.9' %}
  include:
    - project.packages5
  {% endfor %}


{% endif %}
Reply all
Reply to author
Forward
0 new messages