From bd4003e3f2f2608db0036bd885ad4eca0fb5bd0c Mon Sep 17 00:00:00 2001 From: Will Thames Date: Mon, 27 Feb 2017 14:38:09 +1000 Subject: [PATCH] Add tags to cloudfront distribution facts Tags are available from cloudfront API, so make use of them --- .../modules/cloud/amazon/cloudfront_facts.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/cloudfront_facts.py b/lib/ansible/modules/cloud/amazon/cloudfront_facts.py index 9aa67b56d0..c905235dd4 100644 --- a/lib/ansible/modules/cloud/amazon/cloudfront_facts.py +++ b/lib/ansible/modules/cloud/amazon/cloudfront_facts.py @@ -206,21 +206,18 @@ summary: type: dict ''' -try: - import boto3 - import botocore - HAS_BOTO3 = True -except ImportError: - HAS_BOTO3 = False - -from ansible.module_utils.ec2 import get_aws_connection_info -from ansible.module_utils.ec2 import ec2_argument_spec -from ansible.module_utils.ec2 import boto3_conn +from ansible.module_utils.ec2 import get_aws_connection_info, ec2_argument_spec, boto3_conn, HAS_BOTO3 +from ansible.module_utils.ec2 import boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict from ansible.module_utils.basic import AnsibleModule from functools import partial -import json import traceback +try: + import botocore +except ImportError: + pass # will be caught by imported HAS_BOTO3 + + class CloudFrontServiceManager: """Handles CloudFront Services""" @@ -400,6 +397,8 @@ class CloudFrontServiceManager: invalidation_ids = self.get_list_of_invalidation_ids_from_distribution_id(dist['Id']) if invalidation_ids: temp_distribution.update( { 'Invalidations': invalidation_ids } ) + resource_tags = self.client.list_tags_for_resource(Resource=dist['ARN']) + temp_distribution['Tags'] = boto3_tag_list_to_ansible_dict(resource_tags['Tags'].get('Items', [])) distribution_list[list_name].append(temp_distribution) return distribution_list except Exception as e: