From 6f38d8a471d7832ac20739ff21b241037c19ef3e Mon Sep 17 00:00:00 2001 From: devt Date: Thu, 16 Sep 2021 17:00:07 -0400 Subject: [PATCH 1/5] Fix how it detects changes Most of the times when there are no changes, the change set will have a status FAILED with StatusReason="The submitted information didn't contain changes. Submit different information to create a change set.", but sometimes StatusReason is "No updates are to be performed." when --- plugins/modules/cloudformation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/cloudformation.py b/plugins/modules/cloudformation.py index 998a6ca4296..eba44c53a69 100644 --- a/plugins/modules/cloudformation.py +++ b/plugins/modules/cloudformation.py @@ -449,7 +449,7 @@ def create_changeset(module, stack_params, cfn, events_limit): module.fail_json_aws(err) 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']: + elif newcs['Status'] == 'FAILED' and ("The submitted information didn't contain changes" in newcs['StatusReason'] or "No updates are to be performed" in newcs['StatusReason']): cfn.delete_change_set(aws_retry=True, ChangeSetName=cs['Id']) result = dict(changed=False, output='The created Change Set did not contain any changes to this stack and was deleted.') @@ -594,8 +594,8 @@ def check_mode_changeset(module, stack_params, cfn): reason = description.get('StatusReason') - if description['Status'] == 'FAILED' and "didn't contain changes" in description['StatusReason']: - return {'changed': False, 'msg': reason, 'meta': description['StatusReason']} + if description['Status'] == 'FAILED' and ("didn't contain changes" in reason or "No updates are to be performed" in reason): + return {'changed': False, 'msg': reason, 'meta': reason} return {'changed': True, 'msg': reason, 'meta': description['Changes']} except (botocore.exceptions.ValidationError, botocore.exceptions.ClientError) as err: From dd05c92cbd75871453c97e85c02b2862d82b04cf Mon Sep 17 00:00:00 2001 From: devt Date: Fri, 17 Sep 2021 08:59:52 -0400 Subject: [PATCH 2/5] Update cloudformation.py Fix errors from checks at https://dashboard.zuul.ansible.com/t/ansible/build/9e26ca58308747a8829cef60bd96189c * ERROR: plugins/modules/cloudformation.py:452:133: E271: multiple spaces after keyword * ERROR: plugins/modules/cloudformation.py:452:161: E501: line too long (193 > 160 characters) --- plugins/modules/cloudformation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/cloudformation.py b/plugins/modules/cloudformation.py index eba44c53a69..7ec25a6f225 100644 --- a/plugins/modules/cloudformation.py +++ b/plugins/modules/cloudformation.py @@ -449,7 +449,8 @@ def create_changeset(module, stack_params, cfn, events_limit): module.fail_json_aws(err) 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'] or "No updates are to be performed" in newcs['StatusReason']): + elif newcs['Status'] == 'FAILED' and ("The submitted information didn't contain changes" in newcs['StatusReason'] + or "No updates are to be performed" in newcs['StatusReason']): cfn.delete_change_set(aws_retry=True, ChangeSetName=cs['Id']) result = dict(changed=False, output='The created Change Set did not contain any changes to this stack and was deleted.') From 0347eb6ede17d5967f65eca791dafb190b639992 Mon Sep 17 00:00:00 2001 From: devt Date: Fri, 17 Sep 2021 12:25:34 -0400 Subject: [PATCH 3/5] Fix Trailing whitespace --- plugins/modules/cloudformation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/cloudformation.py b/plugins/modules/cloudformation.py index 7ec25a6f225..f5266b3ae53 100644 --- a/plugins/modules/cloudformation.py +++ b/plugins/modules/cloudformation.py @@ -449,7 +449,7 @@ def create_changeset(module, stack_params, cfn, events_limit): module.fail_json_aws(err) 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'] + elif newcs['Status'] == 'FAILED' and ("The submitted information didn't contain changes" in newcs['StatusReason'] or "No updates are to be performed" in newcs['StatusReason']): cfn.delete_change_set(aws_retry=True, ChangeSetName=cs['Id']) result = dict(changed=False, From a94853a41ffa49768945976023fe57f9a2d994b5 Mon Sep 17 00:00:00 2001 From: devt Date: Tue, 21 Sep 2021 04:16:18 -0500 Subject: [PATCH 4/5] Add changelog fragment Hopefully syntax above conforms to https://cn-ansibledoc.readthedocs.io/zh_CN/latest/community/development_process.html#creating-a-changelog-fragment --- .../fragments/507-fix_cloudformation_changeset_detection.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/fragments/507-fix_cloudformation_changeset_detection.yml diff --git a/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml b/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml new file mode 100644 index 00000000000..4060a67bdb1 --- /dev/null +++ b/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml @@ -0,0 +1,5 @@ +minor_changes: + - cloudformation - fix detection when there are no changes. + Sometimes when there are no changes, the change set will have a status FAILED with StatusReason + No updates are to be performed. + (https://github.com/ansible-collections/amazon.aws/pull/507) From bf7e5cd57b94bdfec8a50b0728022d661350996a Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 6 Oct 2021 13:53:46 +0200 Subject: [PATCH 5/5] Minor formatting tweak to changelog --- .../fragments/507-fix_cloudformation_changeset_detection.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml b/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml index 4060a67bdb1..b9c819b0e13 100644 --- a/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml +++ b/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml @@ -1,5 +1,5 @@ minor_changes: - cloudformation - fix detection when there are no changes. Sometimes when there are no changes, the change set will have a status FAILED with StatusReason - No updates are to be performed. - (https://github.com/ansible-collections/amazon.aws/pull/507) + No updates are to be performed + (https://github.com/ansible-collections/amazon.aws/pull/507).