From 2f64e2c7fb37837daecffd876b9c16b5246e910c Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Tue, 11 Apr 2017 16:15:05 -0400 Subject: [PATCH] [cloud] ec2_asg: check autoscaling group for tags before trying to use them - partially fixes #23234 (#23259) * check autoscaling group for tags before trying to use them * Add warning fix comparison --- lib/ansible/modules/cloud/amazon/ec2_asg.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_asg.py b/lib/ansible/modules/cloud/amazon/ec2_asg.py index 1fd30d43c6..04487cb8c7 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_asg.py +++ b/lib/ansible/modules/cloud/amazon/ec2_asg.py @@ -551,11 +551,14 @@ def create_autoscaling_group(connection, module): want_tags[tag.key] = [tag.value, tag.propagate_at_launch] dead_tags = [] - for tag in as_group.tags: - have_tags[tag.key] = [tag.value, tag.propagate_at_launch] - if tag.key not in want_tags: - changed = True - dead_tags.append(tag) + if getattr(as_group, "tags", None): + for tag in as_group.tags: + have_tags[tag.key] = [tag.value, tag.propagate_at_launch] + if tag.key not in want_tags: + changed = True + dead_tags.append(tag) + elif getattr(as_group, "tags", None) is None and asg_tags: + module.warn("It appears your ASG is attached to a target group. This is a boto2 bug. Tags will be added but no tags are able to be removed.") if dead_tags != []: connection.delete_tags(dead_tags)