title: Ansible: iterate over a list of dictionaries - loop vs. with_items
body: <p>I'm getting different results when using loop vs with_items when trying to iterate over a list of dictionaries.</p>
  
  <p>I've tried using loop|dict2items (the structure isn't a dictionary, &amp; it tells me as much. heh) and loop with the flatten filter.</p>
  
  <p>Here is the list of dictionaries:</p>
  
  <pre><code>    "msg": [
          {
              "id": "id1", 
              "ip": "ip1", 
              "name": "name1"
          }, 
          {
              "id": "id2", 
              "ip": "ip2", 
              "name": "name2"
          }, 
          {
              "id": "id3", 
              "ip": "ip3", 
              "name": "name3"
          }, 
          {
              "id": "id4", 
              "ip": "ip4", 
              "name": "name4"
          }
      ]
  }
  </code></pre>
  
  <p>Here is the task in the playbook:</p>
  
  <pre><code> - name: Add privateIp windows_instances to inventory
          add_host:
            name: "{{ item.ip }}"
            aws_name: "{{ item.name }}"
            groups: windows_instances
            aws_instanceid: "{{ item.id }}"
            ansible_user: "{{ windows_user }}"
            ansible_password: "{{ windows_password }}"
            ansible_port: 5985
            ansible_connection: winrm
            ansible_winrm_server_cert_validation: ignore
          loop:
            - "{{ list1 | flatten(levels=1) }}"
  </code></pre>
  
  <p>When attempting to run the above code, I get the "list object has no attribute" error. I've tried different flatten levels to no avail.</p>
  
  <p><em>HOWEVER...</em></p>
  
  <p>If I simply replace the loop above with:</p>
  
  <pre><code>with_items:
    - "{{ list1 }}"
  </code></pre>
  
  <p>Everything works perfectly. I'm missing something in the with_items > loop translation here...</p>