From fac1405bcced7de066ca50aa0ec47ad4167119e5 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 16 Oct 2018 21:16:10 +0200 Subject: [PATCH] [2.6] route53: fix CAA record ordering for idempotency (#46226) * [aws] route53 module: fix idempotency for CAA records (#46049) * Fixing record order for CAA records to properly handle idempotency. * Add integration tests that reproduce CAA failure (cherry picked from commit a727a1ee6779f92ad4e532dc3934754384e1bc73) * Added changelog. --- .../fragments/46049-route53-caa-ordering.txt | 2 ++ lib/ansible/modules/cloud/amazon/route53.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/46049-route53-caa-ordering.txt diff --git a/changelogs/fragments/46049-route53-caa-ordering.txt b/changelogs/fragments/46049-route53-caa-ordering.txt new file mode 100644 index 00000000000..092ace35191 --- /dev/null +++ b/changelogs/fragments/46049-route53-caa-ordering.txt @@ -0,0 +1,2 @@ +bugfixes: +- "route53 - fix CAA record ordering for idempotency." \ No newline at end of file diff --git a/lib/ansible/modules/cloud/amazon/route53.py b/lib/ansible/modules/cloud/amazon/route53.py index 85890ac73c2..a50d1978eb9 100644 --- a/lib/ansible/modules/cloud/amazon/route53.py +++ b/lib/ansible/modules/cloud/amazon/route53.py @@ -574,6 +574,13 @@ def main(): else: wanted_rset.add_value(v) + need_to_sort_records = (type_in == 'CAA') + + # Sort records for wanted_rset if necessary (keep original list) + unsorted_records = wanted_rset.resource_records + if need_to_sort_records: + wanted_rset.resource_records = sorted(unsorted_records) + sets = invoke_with_throttling_retries(conn.get_all_rrsets, zone.id, name=record_in, type=type_in, identifier=identifier_in) sets_iter = iter(sets) @@ -593,13 +600,14 @@ def main(): identifier_in = str(identifier_in) if rset.type == type_in and decoded_name.lower() == record_in.lower() and rset.identifier == identifier_in: + if need_to_sort_records: + # Sort records + rset.resource_records = sorted(rset.resource_records) found_record = True record['zone'] = zone_in record['type'] = rset.type record['record'] = decoded_name record['ttl'] = rset.ttl - record['value'] = ','.join(sorted(rset.resource_records)) - record['values'] = sorted(rset.resource_records) if hosted_zone_id_in: record['hosted_zone_id'] = hosted_zone_id_in record['identifier'] = rset.identifier @@ -652,6 +660,8 @@ def main(): command = 'UPSERT' else: command = command_in.upper() + # Restore original order of records + wanted_rset.resource_records = unsorted_records changes.add_change_record(command, wanted_rset) if not module.check_mode: