From 53266e31df0954513b585b1f056be42514900f4c Mon Sep 17 00:00:00 2001 From: RobReus Date: Wed, 17 Jan 2018 17:00:28 +0100 Subject: [PATCH] Work-around for empty changesets with status FAILED being created (#34933) * Added check to prevent failed empty changesets from being left behind * Fixing comments from PR 34933, prevent infinte loop and stricter exception catching --- .../modules/cloud/amazon/cloudformation.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/ansible/modules/cloud/amazon/cloudformation.py b/lib/ansible/modules/cloud/amazon/cloudformation.py index 48e6d6aa91b..bfd1e25bf6e 100644 --- a/lib/ansible/modules/cloud/amazon/cloudformation.py +++ b/lib/ansible/modules/cloud/amazon/cloudformation.py @@ -346,6 +346,25 @@ def create_changeset(module, stack_params, cfn): result = dict(changed=False, output='ChangeSet %s already exists.' % changeset_name, warnings=[warning]) else: cs = cfn.create_change_set(**stack_params) + # Make sure we don't enter an infinite loop + time_end = time.time() + 600 + while time.time() < time_end: + try: + newcs = cfn.describe_change_set(ChangeSetName=cs['Id']) + except botocore.exceptions.BotoCoreError as err: + error_msg = boto_exception(err) + module.fail_json(msg=error_msg) + if newcs['Status'] == 'CREATE_PENDING' or newcs['Status'] == 'CREATE_IN_PROGRESS': + time.sleep(1) + elif newcs['Status'] == 'FAILED' and "The submitted information didn't contain changes" in newcs['StatusReason']: + cfn.delete_change_set(ChangeSetName=cs['Id']) + result = dict(changed=False, + output='Stack is already up-to-date, Change Set refused to create due to lack of changes.') + module.exit_json(**result) + else: + break + # Lets not hog the cpu/spam the AWS API + time.sleep(1) result = stack_operation(cfn, stack_params['StackName'], 'CREATE_CHANGESET') result['warnings'] = ['Created changeset named %s for stack %s' % (changeset_name, stack_params['StackName']), 'You can execute it using: aws cloudformation execute-change-set --change-set-name %s' % cs['Id'],