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

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 :slight_smile: !

Thanks!
Alex

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

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

command: elbadmin -r eu-west-1 list

Hi All,

I’ve done some work around this, for those that are interested :
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