title: Ansible querying AWS AMIs
body: <p>I'm trying to query AWS EC2 AMIs from Ansible but keep running into an error when looping through the results:</p>
  
  <pre><code>- hosts: localhost
  
    tasks:
     - name: Get AMI
       ec2_ami_facts:
          owner: amazon
          filters:
             architecture: x86_64
             root-device-type: ebs
       register: amis
  
     - name: return filtered data
       debug:
          msg: "{{ item }}"
       loop: " {{ amis \
          | json_query( 'Images[?Description!=`null`] \
          | [?starts_with(Description,`Amazon Linux`)]' ) \
          }} "
  </code></pre>
  
  <p>The idea is to return the image documents, and later just the image IDs with more filtering (end goal is to get the most recent ami id for a given description). But with the current example, and anything else I try I get this error:</p>
  
  <pre><code>TASK [return filtered data] ****************************************************
  fatal: [localhost]: FAILED! =&gt; {"msg": "Invalid data passed to 'loop',
   it requires a list, got this instead:   . Hint: If you passed a
   list/dict of just one element, try adding wantlist=True to your lookup
   invocation or use q/query instead of lookup."}
  </code></pre>
  
  <p>I can look at the 'amis' in its entirety and it looks good, but any filtering I try fails. What is the correct method?</p>