Hello
I am trying to create a shell-script to initiate a new instance and add it to a existing elb. This script will be called later by our monitoring tool to avoid downtime of a service, if the exsting instances fail.
For adding the new instance to the existing elb, this is what I am doing in the script:
ansible localhost -i hosts -m ec2_elb -a “ec2_elbs=${ec2_elbs} ec2_access_key=${ec2_access_key} ec2_secret_key=${ec2_secret_key} instance_id=${instance_id} state=present”
ec2_elbs, contains a string with the name of the elb from the ec2 management console, the instance_id is a string which is filled up by the output of the ec2 module, which is runned before.
I don’t know why, but the statement always returns:
localhost | success >> {
“ansible_facts”: {
“ec2_elbs”:
},
“changed”: false
}
What I am doing wrong?
It sounds like the changed detection on the ec2_elb module just isn’t good, and it should be returning changed=True. Can you please make sure this is filed in github.
** Also as a public service announcement in Ansible 1.2 and later, I highly encourage standardization on "{{ var }} vs “${var}” for templating. This won’t fix the above, but will make me happy
I believe the reason why it’s returning “changed”: false in this particular case is because it didn’t register or deregister your instance.
Returning “ec2_elbs” as an empty list is telling since this would normally contain the elbs that it operated on.
The module is doing something like
elb = boto.connect_elb(self.ec2_access_key, self.ec2_secret_key)
elbs = elb.get_all_load_balancers()
lbs = sorted(lb for lb in elbs if lb.name in ec2_elbs)
What you will want to check is the contents of “ec2_elbs” and whether your AWS account can see the elb(s) you are passing in.
It probably makes sense for the module to fail in the case where we try to register an instance and the elb lookup fails.
-John
Further to this check the region your ELB is in. Region support was just recently added to this module in devel.
Also, John +1.