title: jinja2 - loop through a dictionary
body: <p>I am new with <code>Jinja2</code> maybe my question is noobie but I can't understand it.</p>
  
  <p>So I use <code>Jinja2</code> for an <code>Ansible</code> task as a template to create a file, I have a dictionary defined in the Default Variable file like: </p>
  
  <pre><code>test123:
    testA:
      name: test1
      number: 1
      path: /tmp/test.txt
    testB:
      name: test2
      number: 2
      path: /tmp/test.txt
  </code></pre>
  
  <p>Now in my <code>Jinja2</code> file, I want to loop through this dictionary and print everything defined in the dictionary. </p>
  
  <p>I tried various examples but nothing does the right thing. </p>
  
  <p>For example: </p>
  
  <pre><code>{% for item in test123.values() -%}
  {{ item.name }}="{{ item.number }}"
  {%- endfor %} 
  {% for item in test123.testB.values() -%}
      {{ item.name }}="{{ item.number }}"
  {%- endfor %} 
  </code></pre>
  
  <p>Error Message: </p>
  
  <blockquote>
    <p>fatal: [testserver]: FAILED! => {"changed": false, "msg":
    "AnsibleUndefinedVariable:
    'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute
    'name'"}</p>
  </blockquote>
  
  <p>I thought maybe the best thing would be to create a while loop for this and print everything out but since in <code>Jinja2</code> there is no while loop I am a little bit confused how to do it. </p>
  
  <p>Do someone has an idea how to achieve that? So once again the goal is to print everything from the dictionary in the <code>Jinja2</code> file. </p>
  
  <p>Thank you in advance</p>