# Lost ELB on playbook failure

**URL:** <https://forum.ansible.com/t/lost-elb-on-playbook-failure/19866>\
**Category:** Ansible Project\
**Created:** [November 26, 2015, 3:46pm UTC](https://forum.ansible.com/t/lost-elb-on-playbook-failure/19866 "2015-11-26T15:46:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.ansible.com/u/David_Gonzalez)\
**Post date:** [November 26, 2015, 3:46pm UTC](https://forum.ansible.com/t/lost-elb-on-playbook-failure/19866/1 "2015-11-26T15:46:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kcheng](https://avatars.discourse-cdn.com/v4/letter/k/e9bcb4/32.png) [@kcheng](https://forum.ansible.com/u/kcheng)\
**Post date:** [November 27, 2015, 7:53am UTC](https://forum.ansible.com/t/lost-elb-on-playbook-failure/19866/2 "2015-11-27T07:53:13Z")

</div>

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
