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

91 views
Skip to first unread message

Alex Leonhardt

unread,
Apr 13, 2015, 8:12:23 AM4/13/15
to ansible...@googlegroups.com
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

Alex Leonhardt

unread,
Apr 15, 2015, 10:01:13 AM4/15/15
to ansible...@googlegroups.com

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


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a86de61f-7782-4fd9-b332-6ee83e9a381b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ddffgpmfn

unread,
Apr 16, 2015, 12:13:44 PM4/16/15
to ansible...@googlegroups.com
Looked recently. Ended up using boto's elbadmin and cutting the output up.

command: elbadmin -r eu-west-1 list

Alex Leonhardt

unread,
Apr 18, 2015, 3:05:24 PM4/18/15
to ansible...@googlegroups.com
Hi All,

I’ve done some work around this, for those that are interested : 

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



Reply all
Reply to author
Forward
0 new messages