# details of instance value

**URL:** <https://forum.ansible.com/t/details-of-instance-value/28372>\
**Category:** Ansible Project\
**Created:** [August 20, 2018, 5:27pm UTC](https://forum.ansible.com/t/details-of-instance-value/28372 "2018-08-20T17:27:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 20, 2018, 5:27pm UTC](https://forum.ansible.com/t/details-of-instance-value/28372/1 "2018-08-20T17:27:53Z")

</div>

Hi,  
Could you please help … am unable to retrieve the public ip address of the ec2 instance to add it to the host inventory…

- name: Create an ec2 instance  
ec2:  
key\_name: “{{ keypair }}”  
group: sg\_webserver\_group  
instance\_type: “{{ instance\_type}}”  
image: “{{ ami }}”  
wait: true  
region: “{{ region }}”  
assign\_public\_ip: yes  
register: ec2

- debug: **var=ec2.instances.public\_ip** ( **or var=ec2.public\_ip doesnt give the public ip rather gives undefined variable but whereas var=ec2** gives all the details)

- name: Add the newly created host  
add\_host:  
name: “{{ item.public\_ip }}”  
groups: webserver  
with\_items: “{{ ec2.instances }}”
