From ec2e0279807729b04dbaaf6477758fa6f75c10ff Mon Sep 17 00:00:00 2001 From: Julien Vey Date: Wed, 21 Mar 2018 13:16:42 +0100 Subject: [PATCH] cloudfront_distribution: fix the order of headers to avoid updates again and again (#37340) * Fix python2/3 compatibilities issues * Sort cloudfront_distribution headers to avoid useless updates --- .../modules/cloud/amazon/cloudfront_distribution.py | 8 +++++--- .../targets/cloudfront_distribution/defaults/main.yml | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/cloudfront_distribution.py b/lib/ansible/modules/cloud/amazon/cloudfront_distribution.py index ad082736a42..342847c0abe 100644 --- a/lib/ansible/modules/cloud/amazon/cloudfront_distribution.py +++ b/lib/ansible/modules/cloud/amazon/cloudfront_distribution.py @@ -1405,10 +1405,10 @@ class CloudFrontValidationManager(object): all_origins[origin['domain_name']] = origin new_domains.append(origin['domain_name']) if purge_origins: - for domain in all_origins: + for domain in list(all_origins.keys()): if domain not in new_domains: del(all_origins[domain]) - return ansible_list_to_cloudfront_list(all_origins.values()) + return ansible_list_to_cloudfront_list(list(all_origins.values())) except Exception as e: self.module.fail_json_aws(e, msg="Error validating distribution origins") @@ -1488,7 +1488,7 @@ class CloudFrontValidationManager(object): if purge_cache_behaviors: for target_origin_id in set(all_cache_behaviors.keys()) - set([cb['path_pattern'] for cb in cache_behaviors]): del(all_cache_behaviors[target_origin_id]) - return ansible_list_to_cloudfront_list(all_cache_behaviors.values()) + return ansible_list_to_cloudfront_list(list(all_cache_behaviors.values())) except Exception as e: self.module.fail_json_aws(e, msg="Error validating distribution cache behaviors") @@ -1540,6 +1540,8 @@ class CloudFrontValidationManager(object): forwarded_values = dict() existing_config = config.get('forwarded_values', {}) headers = forwarded_values.get('headers', existing_config.get('headers', {}).get('items')) + if headers: + headers.sort() forwarded_values['headers'] = ansible_list_to_cloudfront_list(headers) if 'cookies' not in forwarded_values: forward = existing_config.get('cookies', {}).get('forward', self.__default_cache_behavior_forwarded_values_forward_cookies) diff --git a/test/integration/targets/cloudfront_distribution/defaults/main.yml b/test/integration/targets/cloudfront_distribution/defaults/main.yml index ce7d1ebc417..7cf4e1be443 100644 --- a/test/integration/targets/cloudfront_distribution/defaults/main.yml +++ b/test/integration/targets/cloudfront_distribution/defaults/main.yml @@ -1,12 +1,16 @@ -cloudfront_hostname: "{{ resource_prefix | lower }}01" +cloudfront_hostname: "{{ resource_prefix }}01" # Use a domain that has a wildcard DNS -cloudfront_alias: "{{ cloudfront_hostname | lower }}.github.io" +cloudfront_alias: "{{ cloudfront_hostname }}.github.io" cloudfront_test_cache_behaviors: - path_pattern: /test/path forwarded_values: headers: - Host + - X-HTTP-Forwarded-For + - CloudFront-Forwarded-Proto + - Origin + - Referer allowed_methods: items: - GET