# Access each object in "with\_items"

**URL:** <https://forum.ansible.com/t/access-each-object-in-with-items/19234>\
**Category:** Ansible Developer\
**Created:** [September 11, 2015, 12:04am UTC](https://forum.ansible.com/t/access-each-object-in-with-items/19234 "2015-09-11T00:04:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anirudh\_Seshagirisa](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Anirudh\_Seshagirisa](https://forum.ansible.com/u/Anirudh_Seshagirisa)\
**Post date:** [September 11, 2015, 12:04am UTC](https://forum.ansible.com/t/access-each-object-in-with-items/19234/1 "2015-09-11T00:04:53Z")

</div>

Hello All,

I have a simple question regarding ansible script with ec2-instances.

My code is the following.

- name: add host\_name

with\_items: ec2.instances

I know item.public\_id gives the public ip, but how do i get the public\_ip of the first instance in that list ? Do I just do item[0].public\_ip ? It is not working for me.

Any help is appreciated.
