# get private ip of instances behind ec2 elastic load balancer

**URL:** <https://forum.ansible.com/t/get-private-ip-of-instances-behind-ec2-elastic-load-balancer/21393>\
**Category:** Ansible Project\
**Created:** [May 10, 2016, 1:03pm UTC](https://forum.ansible.com/t/get-private-ip-of-instances-behind-ec2-elastic-load-balancer/21393 "2016-05-10T13:03:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurabh.jha](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@saurabh.jha](https://forum.ansible.com/u/saurabh.jha)\
**Post date:** [May 10, 2016, 1:03pm UTC](https://forum.ansible.com/t/get-private-ip-of-instances-behind-ec2-elastic-load-balancer/21393/1 "2016-05-10T13:03:38Z")

</div>

Dear all,

I am new to ansible, I want to populate my host file by finding the private ip of instances which are behind the ec2 elb. So that my inventory file is consistent with actual running instances.  
I don’t seem to find a way to do that. any pointer will be helpful.

Thanks,  
Saurabh J

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 10, 2016, 6:00pm UTC](https://forum.ansible.com/t/get-private-ip-of-instances-behind-ec2-elastic-load-balancer/21393/2 "2016-05-10T18:00:16Z")

</div>

You can get the instance id by using this task:

- name: Get the facts about the ELB  
ec2\_elb\_facts:  
names: rbgeek-dev-web-elb  
region: “eu-west-1”  
register: elb\_facts

- name: Instance(s) ID that are currently register to the ELB  
debug:  
msg: “{{ elb\_facts.elbs.0.instances }}”

Then you can use the ec2\_id to get it’s ip address, may be a minor modification to this [plugin](https://github.com/jonhadfield/ansible-lookups/blob/master/v2/aws_ec2_instance_private_ip_from_name.py) help you or you can find some other way to get it done.

Hope that point you to the right direction.
