Deregister EC2 instances from an ELB one by one, transnsfer a .deb package & install and register each onto same ELB back.

Hi,

I am new to Ansible and trying to automate the following scenario on AWS:

  1. Get the instance ids registered to an elb from within an elb. (I do not want to specify the instaces in a harcoded way)
  2. Deregister one instance and perform my needed operation in that instance (e.g. edit /var/lib/monit/id )
  3. Register that instance back into the same elb. Repeat the same until all instances in that elb are updated/upgraded.

I tried follwoing:

  • ec2_elb_facts for instance ids (it does not provide host name or public ids) and create a group for the instances
  • ec2_elb to deregister instances using the group created above
  • I am not sure how to log into the instances on the fly as ec2_elb_facts does not provide hostname or IPs.

Can anyone please help me on this ? If anyone can provide me the scripts, that would be of great help.

Thanks,

Raj.