From cb4db82354563ca978a6f933e343cfa0b3ff5ea0 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 3 May 2018 14:29:57 +0200 Subject: [PATCH] Route53 check mode (#37273) * Adding check mode for route53. * flake8 --- lib/ansible/modules/cloud/amazon/route53.py | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/route53.py b/lib/ansible/modules/cloud/amazon/route53.py index 0350ac5c5a2..85890ac73c2 100644 --- a/lib/ansible/modules/cloud/amazon/route53.py +++ b/lib/ansible/modules/cloud/amazon/route53.py @@ -364,7 +364,6 @@ import distutils.version try: import boto import boto.ec2 - from boto import route53 from boto.route53 import Route53Connection from boto.route53.record import Record, ResourceRecordSets from boto.route53.status import Status @@ -436,6 +435,7 @@ def commit(changes, retry_interval, wait, wait_timeout): raise TimeoutError() return result + # Shamelessly copied over from https://git.io/vgmDG IGNORE_CODE = 'Throttling' MAX_RETRIES = 5 @@ -491,7 +491,7 @@ def main(): mutually_exclusive = [('failover', 'region', 'weight')] module = AnsibleModule(argument_spec=argument_spec, required_together=required_together, required_if=required_if, - mutually_exclusive=mutually_exclusive) + mutually_exclusive=mutually_exclusive, supports_check_mode=True) if not HAS_BOTO: module.fail_json(msg='boto required for this module') @@ -654,17 +654,18 @@ def main(): command = command_in.upper() changes.add_change_record(command, wanted_rset) - try: - result = invoke_with_throttling_retries(commit, changes, retry_interval_in, wait_in, wait_timeout_in) - except boto.route53.exception.DNSServerError as e: - txt = e.body.split("")[1] - txt = txt.split("")[0] - if "but it already exists" in txt: - module.exit_json(changed=False) - else: - module.fail_json(msg=txt) - except TimeoutError: - module.fail_json(msg='Timeout waiting for changes to replicate') + if not module.check_mode: + try: + invoke_with_throttling_retries(commit, changes, retry_interval_in, wait_in, wait_timeout_in) + except boto.route53.exception.DNSServerError as e: + txt = e.body.split("")[1] + txt = txt.split("")[0] + if "but it already exists" in txt: + module.exit_json(changed=False) + else: + module.fail_json(msg=txt) + except TimeoutError: + module.fail_json(msg='Timeout waiting for changes to replicate') module.exit_json(changed=True)