Access each object in "with_items"

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.