From 54466fa809ffc58defc2ba8fc69b42de4afd7613 Mon Sep 17 00:00:00 2001 From: Kaz Cheng Date: Mon, 27 Nov 2017 16:51:38 +1000 Subject: [PATCH] Update facts module to present ansible_friendly tags dictionary on returned nat gateways (#33294) --- .../cloud/amazon/ec2_vpc_nat_gateway_facts.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_nat_gateway_facts.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_nat_gateway_facts.py index 648ea277037..a7b29576afa 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_nat_gateway_facts.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_nat_gateway_facts.py @@ -89,7 +89,7 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.ec2 import (ec2_argument_spec, get_aws_connection_info, boto3_conn, - camel_dict_to_snake_dict, ansible_dict_to_boto3_filter_list, HAS_BOTO3) + camel_dict_to_snake_dict, ansible_dict_to_boto3_filter_list, boto3_tag_list_to_ansible_dict, HAS_BOTO3) def date_handler(obj): @@ -98,6 +98,7 @@ def date_handler(obj): def get_nat_gateways(client, module, nat_gateway_id=None): params = dict() + nat_gateways = list() params['Filter'] = ansible_dict_to_boto3_filter_list(module.params.get('filters')) params['NatGatewayIds'] = module.params.get('nat_gateway_ids') @@ -107,7 +108,16 @@ def get_nat_gateways(client, module, nat_gateway_id=None): except Exception as e: module.fail_json(msg=str(e.message)) - return [camel_dict_to_snake_dict(gateway) for gateway in result['NatGateways']] + for gateway in result['NatGateways']: + # Turn the boto3 result into ansible_friendly_snaked_names + converted_gateway = camel_dict_to_snake_dict(gateway) + if 'tags' in converted_gateway: + # Turn the boto3 result into ansible friendly tag dictionary + converted_gateway['tags'] = boto3_tag_list_to_ansible_dict(converted_gateway['tags']) + + nat_gateways.append(converted_gateway) + + return nat_gateways def main():