Repository: ansible/ansible
Pull request: Fixes #24578: ROLLBACK_COMPLETE is a failure state
##### SUMMARY
Fixes #24578. When CloudFormation fails to create stack and ends up in ROLLBACK_COMPLETED status, should be a failure state for this module.

##### ISSUE TYPE
 - Bugfix Pull Request

##### COMPONENT NAME
cloudformation

##### ANSIBLE VERSION
```
ansible 2.3.0.0
  config file = /Users/jose.armesto/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Feb  7 2017, 22:08:53) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
```



Problem statement:
Ansible should fail when CloudFormation ends up in a `ROLLBACK_COMPLETE` status
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
cloudformation

##### ANSIBLE VERSION
```
ansible 2.3.0.0
  config file = /Users/jose.armesto/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Feb  7 2017, 22:08:53) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
```

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### SUMMARY
Ansible should fail when CloudFormation ends up in a `ROLLBACK_COMPLETE` status.

##### EXPECTED RESULTS
```
PLAY RECAP *********************************************************************
localhost                  : ok=33   changed=8    unreachable=0    failed=1  
```

##### ACTUAL RESULTS
```
PLAY RECAP *********************************************************************
localhost                  : ok=33   changed=8    unreachable=0    failed=0
```

Hints from issue discussion:
cc @tedder @ryansb
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
It seems like in the boto3 rewrite, [the case when the stack status was ROLLBACK_COMPLETE was forgotten](https://github.com/ansible/ansible-modules-core/commit/f040d63403f6c459a278918fa48fa8cb87754506#diff-68a48645e655d4879298e03d72b70d11L205).

Commit message: ROLLBACK_COMPLETE is a failure state

Fixes #24578

Patch to review:
diff --git a/lib/ansible/modules/cloud/amazon/cloudformation.py b/lib/ansible/modules/cloud/amazon/cloudformation.py
index 6f8a6e2984250f..3bb407f847e109 100644
--- a/lib/ansible/modules/cloud/amazon/cloudformation.py
+++ b/lib/ansible/modules/cloud/amazon/cloudformation.py
@@ -343,7 +343,7 @@ def stack_operation(cfn, stack_name, operation):
             else:
                 ret.update({'changed': False, 'failed': True, 'output' : 'Stack not found.'})
                 return ret
-        elif stack['StackStatus'].endswith('_ROLLBACK_COMPLETE'):
+        elif stack['StackStatus'].endswith('ROLLBACK_COMPLETE'):
             ret.update({'changed': True, 'failed' :True, 'output': 'Problem with %s. Rollback complete' % operation})
             return ret
         # note the ordering of ROLLBACK_COMPLETE and COMPLETE, because otherwise COMPLETE will match both cases.


Code review comments:
diff_hunk: @@ -343,7 +343,7 @@ def stack_operation(cfn, stack_name, operation):
             else:
                 ret.update({'changed': False, 'failed': True, 'output' : 'Stack not found.'})
                 return ret
-        elif stack['StackStatus'].endswith('_ROLLBACK_COMPLETE'):
+        elif stack['StackStatus'].endswith('ROLLBACK_COMPLETE'):
path: lib/ansible/modules/cloud/amazon/cloudformation.py
text: @user1:
Hmm. Should `UPDATE_ROLLBACK_COMPLETE` and `ROLLBACK_COMPLETE` return in the same manner? I can't think of a reason not, but want to make sure we acknowledge it and linking to [the list of possible states](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html#w1ab2c15c17c21c13). Perhaps a comment indicating these states are covered? Also, can you fix the spacing on `'failed' :True`? Not your fault, but I see it now.