title: Saltstack - Parsing YAML properties file to set Jinja variables - For loop
body: <p>I try to parse a propertie file with Jinja for setting variables.</p>
  <p>I have mutiple categories and sub-categories in this file like :</p>
  <ul>
  <li>jboss_container
  <ul>
  <li>some properties</li>
  <li>foobar</li>
  </ul>
  </li>
  <li>jboss_datasource_install
  <ul>
  <li>datasource1
  <ul>
  <li>prop1</li>
  <li>prop2</li>
  </ul>
  </li>
  <li>datasource2</li>
  </ul>
  </li>
  <li>jboss_app_deploy
  <ul>
  <li>app1</li>
  <li>app2</li>
  </ul>
  </li>
  </ul>
  <p>The goal is to set variables from each categories and reuse them in for loop.
  --&gt; For Example, i want to install 2 jboss datasources and loop on each sub-categories</p>
  <p><strong>foobar.properties.yml :</strong></p>
  <pre><code>jboss_container:
      jboss_container_values:
        jboss_container_install: 'True'
        jboss_app_name: 'foobar'
        jboss_version: 'x.x.x'
        ...
  
  jboss_datasource_install:
      datasource1:
        jboss_datasource_install: 'True'
        jboss_datasource_name: 'foobar'
        jboss_datasource_jta: 'true'
        ...
      datasource2:
        jboss_datasource_install: 'True'
        ...
  </code></pre>
  <p><strong>init.sls :</strong></p>
  <pre><code>{% import_yaml 'foobar_properties.yml' as jboss_apps %}
  
  % for jboss_container, jboss_container_values in jboss_apps.iteritems() %}
        {% for key, value in jboss_container_values.items() %}
                    {% if value.get('jboss_container_install') != 'False' %}
  
  # Do stuff - {{ value.jboss_app_name }}
  
                    {% endif %}
        {% endfor %}
  {% endfor %}
  
  {% for jboss_datasource_install, jboss_datasource_install_name in jboss_apps.iteritems() %}
        {% for key, value in jboss_datasource_install_name.items() %}
                    {% if value.get('jboss_datasource_install') != 'False' %}
  
  # Do stuff - {{ value.jboss_datasource_install }}
  
                    {% endif %}
        {% endfor %}
  {% endfor %}
  </code></pre>
  <p>Actually occurs this error in Salt :</p>
  <p><em><strong>Jinja variable 'dict object' has no attribute 'jboss_app_name'</strong></em></p>
  <p>Any Ideas How to do this?</p>
  <p>Many thanks :)</p>
  <p><strong>UPD:</strong></p>
  <p>Unfortunately with :</p>
  <pre><code>{% for key, value in jboss_apps['jboss_container']['jboss_container_values'].iteritems() %} 
  {% if value.get('jboss_container_install') == 'True' %}
  # Do stuff - {{ value.jboss_app_name }}
  </code></pre>
  <p>I got this error : <code>failed: Jinja variable 'str object' has no attribute 'get'</code></p>
  <p>Without the If statement, I got this error : <code>failed: Jinja variable 'str object' has no attribute 'jboss_app_name'</code></p>
  <p>And if i try with <code>{{ jboss_app_name }}</code> rather than <code>{{ value.jboss_app_name }}</code>, same error occurs.</p>