# Can I get a list of existing ELBs in a VPC ?

**URL:** <https://forum.ansible.com/t/can-i-get-a-list-of-existing-elbs-in-a-vpc/17962>\
**Category:** Ansible Project\
**Created:** [April 12, 2015, 4:44pm UTC](https://forum.ansible.com/t/can-i-get-a-list-of-existing-elbs-in-a-vpc/17962 "2015-04-12T16:44:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Leonhardt](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Alex\_Leonhardt](https://forum.ansible.com/u/Alex_Leonhardt)\
**Post date:** [April 12, 2015, 4:44pm UTC](https://forum.ansible.com/t/can-i-get-a-list-of-existing-elbs-in-a-vpc/17962/1 "2015-04-12T16:44:33Z")

</div>

Hi,

I’m trying to get a list of ELBs to then use that to add new instances that I create to these ELBs, but am not successful - the ec2\_elbs is always empty when checking. I’m currently trying the basic example that’s meant to add new instances to a ELB, however, I try to do this without knowing the ELBs name(s). Is that even possible ? If so, it’d be great if there was a link to a doc or blog or something on who to get that list of ELBs ?

Example:

`

- hosts: tag\_Name\_Demo:&tag\_Svc\_Apache  
gather\_facts: true  
user: ec2-user

# basic pre\_task and post\_task example

pre\_tasks:

- name: Gathering ec2 facts  
action: ec2\_facts

- name: Instance De-register  
local\_action:  
module: ec2\_elb  
region: eu-west-1  
instance\_id: “{{ ansible\_ec2\_instance\_id }}”  
state: ‘absent’

tasks:

- name: install httpd  
sudo: yes  
yum: name=httpd state=present

- name: ensure httpd is running  
sudo: yes  
service: name=httpd state=started

- name: Check NTP service  
sudo: yes  
service: name=ntpd state=started

post\_tasks:

- debug: msg=“{{ item }}”  
with\_items: ec2\_elbs

- name: Instance Register  
local\_action:  
module: ec2\_elb  
region: eu-west-1  
instance\_id: “{{ ansible\_ec2\_instance\_id }}”  
ec2\_elbs: “{{ item }}”  
state: ‘present’  
wait: yes  
ignore\_errors: yes  
with\_items: ec2\_elbs

`

The output i get :

`

PLAY [tag\_Name\_Demo:&tag\_Svc\_Apache] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [52.17.75.238]  
ok: [52.17.52.33]

TASK: [Gathering ec2 facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [52.17.75.238]  
ok: [52.17.52.33]

TASK: [Instance De-register] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [52.17.75.238 → 127.0.0.1]  
ok: [52.17.52.33 → 127.0.0.1]

TASK: [install httpd] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [52.17.52.33]  
ok: [52.17.75.238]

TASK: [ensure httpd is running] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [52.17.75.238]  
ok: [52.17.52.33]

TASK: [Check NTP service] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [52.17.52.33]  
ok: [52.17.75.238]

TASK: [debug msg=“{{ item }}”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [52.17.52.33]  
skipping: [52.17.75.238]

TASK: [Instance Register] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [52.17.52.33]  
skipping: [52.17.75.238]

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
52.17.52.33 : ok=6 changed=0 unreachable=0 failed=0  
52.17.75.238 : ok=6 changed=0 unreachable=0 failed=0

`

Maybe I’m missing the obvious .. the creation of the ELBs is done in a separate play as I want to be able to run the two plays, create environment and create instances, separately. But maybe I can’t do that, so your advice would be very useful 🙂 !

Thanks!  
Alex

---

<div class="post-metadata">

**Author:** ![Alex\_Leonhardt](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Alex\_Leonhardt](https://forum.ansible.com/u/Alex_Leonhardt)\
**Post date:** [April 15, 2015, 2:01pm UTC](https://forum.ansible.com/t/can-i-get-a-list-of-existing-elbs-in-a-vpc/17962/2 "2015-04-15T14:01:04Z")

</div>

Hi,

Since there’s no reply - possible to get someone at ansible to check / comment ? It seems similar to a question regarding VPCs that was recently asked and also has no answers yet?

In fact, when creating the ELBs, can I keep a local list of them thats being produced by the playbook, if I can’t get it dynamically?

Thanks!  
Alex

---

<div class="post-metadata">

**Author:** ![Tom\_Paine](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tom\_Paine](https://forum.ansible.com/u/Tom_Paine)\
**Post date:** [April 16, 2015, 4:13pm UTC](https://forum.ansible.com/t/can-i-get-a-list-of-existing-elbs-in-a-vpc/17962/3 "2015-04-16T16:13:44Z")

</div>

Looked recently. Ended up using boto’s elbadmin and cutting the output up.

command: elbadmin -r eu-west-1 list

---

<div class="post-metadata">

**Author:** ![Alex\_Leonhardt](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Alex\_Leonhardt](https://forum.ansible.com/u/Alex_Leonhardt)\
**Post date:** [April 18, 2015, 7:05pm UTC](https://forum.ansible.com/t/can-i-get-a-list-of-existing-elbs-in-a-vpc/17962/4 "2015-04-18T19:05:15Z")

</div>

Hi All,

I’ve done some work around this, for those that are interested :  
[https://github.com/alex-leonhardt/ansible-modules-core/commit/2c3f7928b8995ec7c6903da6c507643efcad6d1d](https://github.com/alex-leonhardt/ansible-modules-core/commit/2c3f7928b8995ec7c6903da6c507643efcad6d1d)

I can’t see where / how to run some unit tests for this module, so I can’t verify if I broke something by changing this, however, creating, listing and deleting ELBs seems to work just fine. I’ve also updated the documentation / examples so you can clone and try yourself if needed.

Please let me know what you think.

Alex
