Rotate groups out of load balancer

37 views
Skip to first unread message

Jesse Macnish

unread,
May 28, 2015, 5:55:39 PM5/28/15
to ansible...@googlegroups.com
Apologies in advance here: I'm missing something fundamental.

I'm trying to do something pretty simple: I'm putting new code into a QA environment, and would like to remove old machines out of a elastic load balancer and substitute in new machines.  I have something that looks like:

---
# rotate.yml
# NOTE: Doesn't work.

- name: Remove all non-new hosts from the QA appserver load balancer
  hosts: tag_Env_qa:&tag_Role_appserver:!tag_Status_new
  connection: local
  vars:
    region: ...
    appserver_elb: dev

  pre_tasks:
  - name: Gathering ec2 facts
    action: ec2_facts

  tasks:
  - name: Remove each host from the ELB
    local_action: ec2_elb
    args:
      instance_id: "{{ ansible_ec2_instance_id }}"
      region:      "{{ region }}"
      ec2_elbs:    "{{ appserver_elb }}"
      state:       'absent'

ec2_elb is failing:  ansible_ec2_instance_id is undefined.  True enough, dumping all variables proves that it's not defined.  From the examples I've come across, it seems like this magic variable is getting set somewhere, but I'm not seeing where or how (I figured ec2_facts would do it).

I feel like it would be more direct to directly interrogate the ELB for it's members and then remove them.  I didn't find an obvious way to do that, so I went about it the other way (trying to leverage groups and tagging things as "new").

I'd also totally believe there is a far better way of getting the same basic result ("instantiate/rotate machines out of ELB"), and would be happy to hear them.

--jesse


Reply all
Reply to author
Forward
0 new messages