get private ip of instances behind ec2 elastic load balancer

54 views
Skip to first unread message

saura...@delhivery.com

unread,
May 10, 2016, 9:38:43 AM5/10/16
to Ansible Project
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

Arbab Nazar

unread,
May 10, 2016, 2:00:16 PM5/10/16
to Ansible Project
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 help you or you can find some other way to get it done.

Hope that point you to the right direction.
Reply all
Reply to author
Forward
0 new messages