Lost ELB on playbook failure

Hi,
I’m deploying my web app using an ansible playbook (Apache+Tomcat+Grails stack).
It’s a web app with serveral frontend web servers, those fronts are behind several Amazons ELBs.
Using Ansibles ec2_facts I get the list of ELBs each machine is present in, then I get it out from those ELBs, deploy the new version, do some other things and bring it back to the ELB.

The problem I’m having is that if the deployment fails while the server is out of the ELB then when I retry to deploy Ansibles ec2_facts returns an empty list so that my server get out of the ELBs.

I asked on Ansibles support and Benno Joy (thanks again dude) suggested using local facts to store the ELB list.

By now I’m working on passing the ELB list as a variable to the playbook so that it’s durable but it forces me to update that list every time I add or delete an ELB.

I’d like other approaches to this problem if any of you has faced with it.

Thanks in advance.

Hi David,

What about using a variable to pass in the tags to gather facts for to get the list of instance ids to add to the load balancer, you can filter on multiple tags if need be?

EG:

ansible-playbook site.yml -e “tags_to_filter=<insert_relevant_tag>” --tags add_to_load_balancer

Then the play looks something like below (replace the relevant part) - so the below will allow you to either use ec2.instances or the remote facts or you could always just use the remote_facts - up to you :

  • name: Get a list of existing instances with listed tags
    ec2_remote_facts:
    region: “{{ region }}”
    filters:

instance-state-name: [running, stopped]
“tag:”: “{{ tags_to_filter }}”
register: existing_instances

tags:

  • add_to_load_balancer
    when: tags_to_filter is defined

  • name: Add instances to load balancer
    ec2_elb:
    instance_id: “{{ item.id }}”
    region: “{{ region }}”
    ec2_elbs: [“<load_balancer_name>”]

state: present
wait: no
with_items: “{{ ec2.instances | default({existing_instances.instances}) }}”

tags:

  • add_to_load_balancer

Karen