title: Using jinja variable as an argument in salt function used in a jinja for loop
body: <p>I've been searching quite a lot but my newbiness prevent me from finding a solution that works !
  Here is my problem (not that complexe, or so I thought) :</p>
  
  <p>My pillar data :</p>
  
  <pre><code>server_access:
    ops: 
      - salt-dev
    ps:
      - client-salt.example.com
    rd:
    ops_trainees:
  </code></pre>
  
  <p>Then my jinja template excerpt :</p>
  
  <pre><code>{% set ldap_search_filter_additionnal = [] %}
  {% for group in ['ops','ps','rd','ops_trainees'] %}
  {% for servers in salt['pillar.get']('server_access:{{ group }}', {}) %}
  {% if grains['fqdn'] == servers %}
  {% set ldap_search_filter_additionnal = ldap_search_filter_additionnal.append('(isMemberOf="cn={{ group }},ou=test,dc=example,dc=com")') %}
  {% endif %}
  {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>I am expecting to loop through the first 4 value, then the second (nested) loop to use each of these 4 value as an argument to the salt function, then if it matches the fqdn add some ldap search filters and so on ...</p>
  
  <p>But it doesn't seems to be possible to use a jinja variable inside the salt function call, is it ?</p>
  
  <p>If not what would you expert advise to get the expected behaviour ?</p>
  
  <p>Bonus : Would you confirm that a jinja loop does not "break" when the if statement is not true ?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE_1</strong> :</p>
  
  <p>After the first propositionof  @Christophe Drevet-Droguet :
  I tried it but I couldn't make it work, or at least match my needs, but I did find something that "kind of" works, unless I only make it work for the first element, with the following try :</p>
  
  <pre><code>{%- set ldap_search_filter_additionnal = [] -%} 
  {%- for server_group, server_name in pillar['server_access'].iteritems() -%} 
  {%- if grains['fqdn'] == server_name[0] -%} 
  {%- set testo = '(isMemberOf=\"cn='+server_group+',ou=interne,dc=example,dc=com\")' -%} 
  {%- set ldap_search_filter_additionnal = ldap_search_filter_additionnal.append(testo) -%} 
  {%- endif -%} 
  {% endfor %}
  </code></pre>
  
  <p>I understand that I match (using the if statement) only the first element because of the "[0]" of "server_name[0]", so far i cannot do any better, so if you have another improvement to make works as I need, please :)</p>
  
  <p><strong>UPDATE_2 :</strong></p>
  
  <p>Ok I finally get the behaviour I was fighting for, but the code is somewhat awkward, so if anyone has tips to make it classier please just throw it down there !</p>
  
  <p>Working solution in answer below.</p>