Skip to content

Commit

Permalink
Work-around for empty changesets with status FAILED being created (an…
Browse files Browse the repository at this point in the history
…sible#34933)

* Added check to prevent failed empty changesets from being left behind

* Fixing comments from PR 34933, prevent infinte loop and stricter exception catching
  • Loading branch information
RobReus authored and ryansb committed Jan 17, 2018
1 parent 9d4d862 commit 53266e3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/ansible/modules/cloud/amazon/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 53266e3

Please sign in to comment.