title: Can I use Jinja2 `map` filter in an Ansible play to get values from an array of objects?
body: <p>I have a playbook for creating some EC2 instances and then doing some stuff with them. The relevant pieces are approximately like:</p>
  
  <pre><code>- name: create ec2 instances
    ec2:
      id: '{{ item.name }}'
      instance_type: '{{ item.type }}'
    register: ec2
    with_items: '{{ my_instance_defs }}'
  - name: wait for SSH
    wait_for:
      host: '{{ item.instances[0].private_ip }}'
      port: 22
    with_items: '{{ ec2.results }}'
  </code></pre>
  
  <p>This works as intended, but I am not especially happy with the <code>item.instances[0].private_ip</code> expression, partly because it shows really large objects in the play summary. I would love to have the <code>with_items</code> part just be an array of IP addresses, rather than an array of objects with arrays of objects inside them. In Python, I would just do something like:</p>
  
  <pre><code>ips = [r['instances'][0]['private_ip'] for r in ec2['results']]
  </code></pre>
  
  <p>And then I would use <code>with_items: '{{ ips }}'</code> in the second task.</p>
  
  <p>Is there a way I can do the same thing using a J2 filter in the YAML of the play? Seems like <a href="http://docs.ansible.com/ansible/playbooks_filters.html#extracting-values-from-containers" rel="noreferrer">http://docs.ansible.com/ansible/playbooks_filters.html#extracting-values-from-containers</a> might be helpful, but I think that presupposes I have an array of keys/indices/whatever.</p>