get private ip of instances behind ec2 elastic load balancer

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

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.