From 7bebc83dcf5af181d36be2cc8a0e9ced0726810c Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Tue, 6 Jun 2017 11:02:15 -0400 Subject: [PATCH] module_utils/ec2: fix boto3 tags to remove (#25277) * Fix boto3 tags to remove; unable to remove a list of strings, need list of {'Key': key} * pep8 fix * cannot bugfix due to differences in AWS APIs - just document * add more info to guidelines for using compare_aws_tags --- lib/ansible/module_utils/ec2.py | 5 +++-- lib/ansible/modules/cloud/amazon/GUIDELINES.md | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index 93d9bee1080..f1fc3d2d097 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -652,13 +652,14 @@ def map_complex_type(complex_type, type_map): def compare_aws_tags(current_tags_dict, new_tags_dict, purge_tags=True): """ Compare two dicts of AWS tags. Dicts are expected to of been created using 'boto3_tag_list_to_ansible_dict' helper function. - Two dicts are returned - the first is tags to be set, the second is any tags to remove + Two dicts are returned - the first is tags to be set, the second is any tags to remove. Since the AWS APIs differ t +hese may not be able to be used out of the box. :param current_tags_dict: :param new_tags_dict: :param purge_tags: :return: tag_key_value_pairs_to_set: a dict of key value pairs that need to be set in AWS. If all tags are identical this dict will be empty - :return: tag_keys_to_unset: a list of key names that need to be unset in AWS. If no tags need to be unset this list will be empty + :return: tag_keys_to_unset: a list of key names (type str) that need to be unset in AWS. If no tags need to be unset this list will be empty """ tag_key_value_pairs_to_set = {} diff --git a/lib/ansible/modules/cloud/amazon/GUIDELINES.md b/lib/ansible/modules/cloud/amazon/GUIDELINES.md index aaf671a2ca1..da7dd0c869f 100644 --- a/lib/ansible/modules/cloud/amazon/GUIDELINES.md +++ b/lib/ansible/modules/cloud/amazon/GUIDELINES.md @@ -314,4 +314,6 @@ to modify and a list of tag key names that you need to remove. Purge is True by existing tags will not be modified. This function is useful when using boto3 'add_tags' and 'remove_tags' functions. Be sure to use the other helper function -'boto3_tag_list_to_ansible_dict' to get an appropriate tag dict before calling this function. +'boto3_tag_list_to_ansible_dict' to get an appropriate tag dict before calling this function. Since the AWS APIs are not +uniform (e.g. EC2 versus Lambda) this will work without modification for some (Lambda) and others may need modification +before using these values (such as EC2, with requires the tags to unset to be in the form [{'Key': key1}, {'Key': key2}]).