From a0e2cdd935a2e50057d7e2b6ac2389137277cd3a Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Sun, 14 Mar 2021 12:34:12 +0100 Subject: [PATCH] fix KeyError: 'Tags' for ec2_instance (#476) * fix key error when ec2 instance has no tags * add changelog fragment --- ...-ec2_instance_fix_key_error_when_instance_has_no_tags.yaml | 2 ++ plugins/modules/ec2_instance.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/476-ec2_instance_fix_key_error_when_instance_has_no_tags.yaml diff --git a/changelogs/fragments/476-ec2_instance_fix_key_error_when_instance_has_no_tags.yaml b/changelogs/fragments/476-ec2_instance_fix_key_error_when_instance_has_no_tags.yaml new file mode 100644 index 00000000000..ac4406fbc17 --- /dev/null +++ b/changelogs/fragments/476-ec2_instance_fix_key_error_when_instance_has_no_tags.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ec2_instance - fix key errors when instance has no tags (https://github.com/ansible-collections/community.aws/pull/476). diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index 380e3527910..18af847aed6 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -889,7 +889,7 @@ def tower_callback_script(tower_conf, windows=False, passwd=None): def manage_tags(match, new_tags, purge_tags, ec2): changed = False - old_tags = boto3_tag_list_to_ansible_dict(match['Tags']) + old_tags = boto3_tag_list_to_ansible_dict(match.get('Tags', {})) tags_to_set, tags_to_delete = compare_aws_tags( old_tags, new_tags, purge_tags=purge_tags, @@ -1559,7 +1559,7 @@ def change_instance_state(filters, desired_state, ec2=None): def pretty_instance(i): instance = camel_dict_to_snake_dict(i, ignore_list=['Tags']) - instance['tags'] = boto3_tag_list_to_ansible_dict(i['Tags']) + instance['tags'] = boto3_tag_list_to_ansible_dict(i.get('Tags', {})) return instance