3

I am trying to use a variable in a "if" statement, this variable is defined in a for loop, but I cannot get it to works, here is a code excerpt :

{% for dir in ['temp','backup','sbin','logs','apps'] %}
  {% if {{ dir }} == 'temp' %}
    /tree/{{ dir }}:
      file.directory:
      - user: user1
      - group: user1
      - mode: 1777
      - makedirs: True
  {% endif %}
  /tree/{{ dir }}:
    file.directory:
      - user: root
      - group: root
      - mode: 755
      - makedirs: True
{% endfor %}

I think the code is self explanatory, if not please ask !

I know my code is not the best looking one, if you have any advices I'd be happy to take them !

Pier
  • 618
  • 2
  • 8
  • 23

1 Answers1

6

Just {% if dir == 'temp' %} would be correct.

EDIT: Typo fixed :)

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • your answer seems to be working (minus the typo around your 'temp' :) ), although I tried this before without luck .... thank you. – Pier Dec 01 '16 at 10:09