|
|
@ -283,7 +283,6 @@ def get_properties(autoscaling_group):
|
|
|
|
if getattr(autoscaling_group, "tags", None):
|
|
|
|
if getattr(autoscaling_group, "tags", None):
|
|
|
|
properties['tags'] = dict((t.key, t.value) for t in autoscaling_group.tags)
|
|
|
|
properties['tags'] = dict((t.key, t.value) for t in autoscaling_group.tags)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return properties
|
|
|
|
return properties
|
|
|
|
|
|
|
|
|
|
|
|
def elb_dreg(asg_connection, module, group_name, instance_id):
|
|
|
|
def elb_dreg(asg_connection, module, group_name, instance_id):
|
|
|
@ -300,7 +299,6 @@ def elb_dreg(asg_connection, module, group_name, instance_id):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
exists = True
|
|
|
|
|
|
|
|
for lb in as_group.load_balancers:
|
|
|
|
for lb in as_group.load_balancers:
|
|
|
|
elb_connection.deregister_instances(lb, instance_id)
|
|
|
|
elb_connection.deregister_instances(lb, instance_id)
|
|
|
|
log.debug("De-registering {0} from ELB {1}".format(instance_id, lb))
|
|
|
|
log.debug("De-registering {0} from ELB {1}".format(instance_id, lb))
|
|
|
@ -321,8 +319,6 @@ def elb_dreg(asg_connection, module, group_name, instance_id):
|
|
|
|
module.fail_json(msg = "Waited too long for instance to deregister. {0}".format(time.asctime()))
|
|
|
|
module.fail_json(msg = "Waited too long for instance to deregister. {0}".format(time.asctime()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def elb_healthy(asg_connection, elb_connection, module, group_name):
|
|
|
|
def elb_healthy(asg_connection, elb_connection, module, group_name):
|
|
|
|
healthy_instances = []
|
|
|
|
healthy_instances = []
|
|
|
|
as_group = asg_connection.get_all_groups(names=[group_name])[0]
|
|
|
|
as_group = asg_connection.get_all_groups(names=[group_name])[0]
|
|
|
@ -339,7 +335,7 @@ def elb_healthy(asg_connection, elb_connection, module, group_name):
|
|
|
|
# but has not yet show up in the ELB
|
|
|
|
# but has not yet show up in the ELB
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
lb_instances = elb_connection.describe_instance_health(lb, instances=instances)
|
|
|
|
lb_instances = elb_connection.describe_instance_health(lb, instances=instances)
|
|
|
|
except boto.exception.InvalidInstance, e:
|
|
|
|
except boto.exception.InvalidInstance:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
for i in lb_instances:
|
|
|
|
for i in lb_instances:
|
|
|
|
if i.state == "InService":
|
|
|
|
if i.state == "InService":
|
|
|
@ -348,7 +344,6 @@ def elb_healthy(asg_connection, elb_connection, module, group_name):
|
|
|
|
return len(healthy_instances)
|
|
|
|
return len(healthy_instances)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def wait_for_elb(asg_connection, module, group_name):
|
|
|
|
def wait_for_elb(asg_connection, module, group_name):
|
|
|
|
region, ec2_url, aws_connect_params = get_aws_connection_info(module)
|
|
|
|
region, ec2_url, aws_connect_params = get_aws_connection_info(module)
|
|
|
|
wait_timeout = module.params.get('wait_timeout')
|
|
|
|
wait_timeout = module.params.get('wait_timeout')
|
|
|
@ -398,7 +393,7 @@ def create_autoscaling_group(connection, module):
|
|
|
|
region, ec2_url, aws_connect_params = get_aws_connection_info(module)
|
|
|
|
region, ec2_url, aws_connect_params = get_aws_connection_info(module)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ec2_connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
|
|
|
|
ec2_connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
|
|
|
|
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
|
|
|
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
elif vpc_zone_identifier:
|
|
|
|
elif vpc_zone_identifier:
|
|
|
|
vpc_zone_identifier = ','.join(vpc_zone_identifier)
|
|
|
|
vpc_zone_identifier = ','.join(vpc_zone_identifier)
|
|
|
@ -435,7 +430,7 @@ def create_autoscaling_group(connection, module):
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
connection.create_auto_scaling_group(ag)
|
|
|
|
connection.create_auto_scaling_group(ag)
|
|
|
|
if wait_for_instances == True:
|
|
|
|
if wait_for_instances:
|
|
|
|
wait_for_new_inst(module, connection, group_name, wait_timeout, desired_capacity, 'viable_instances')
|
|
|
|
wait_for_new_inst(module, connection, group_name, wait_timeout, desired_capacity, 'viable_instances')
|
|
|
|
wait_for_elb(connection, module, group_name)
|
|
|
|
wait_for_elb(connection, module, group_name)
|
|
|
|
as_group = connection.get_all_groups(names=[group_name])[0]
|
|
|
|
as_group = connection.get_all_groups(names=[group_name])[0]
|
|
|
@ -477,7 +472,7 @@ def create_autoscaling_group(connection, module):
|
|
|
|
dead_tags = []
|
|
|
|
dead_tags = []
|
|
|
|
for tag in as_group.tags:
|
|
|
|
for tag in as_group.tags:
|
|
|
|
have_tags[tag.key] = [tag.value, tag.propagate_at_launch]
|
|
|
|
have_tags[tag.key] = [tag.value, tag.propagate_at_launch]
|
|
|
|
if not tag.key in want_tags:
|
|
|
|
if tag.key not in want_tags:
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|
dead_tags.append(tag)
|
|
|
|
dead_tags.append(tag)
|
|
|
|
|
|
|
|
|
|
|
@ -494,14 +489,13 @@ def create_autoscaling_group(connection, module):
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|
as_group.load_balancers = module.params.get('load_balancers')
|
|
|
|
as_group.load_balancers = module.params.get('load_balancers')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if changed:
|
|
|
|
if changed:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
as_group.update()
|
|
|
|
as_group.update()
|
|
|
|
except BotoServerError, e:
|
|
|
|
except BotoServerError, e:
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
if wait_for_instances == True:
|
|
|
|
if wait_for_instances:
|
|
|
|
wait_for_new_inst(module, connection, group_name, wait_timeout, desired_capacity, 'viable_instances')
|
|
|
|
wait_for_new_inst(module, connection, group_name, wait_timeout, desired_capacity, 'viable_instances')
|
|
|
|
wait_for_elb(connection, module, group_name)
|
|
|
|
wait_for_elb(connection, module, group_name)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -836,5 +830,5 @@ def main():
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|
module.exit_json( changed = changed, **asg_properties )
|
|
|
|
module.exit_json( changed = changed, **asg_properties )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|