mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Cloudformation module fix unintentional changed=true
- Don't rewrite the result; this is causing 'changed=true' on update - Move AWSRetry import to top since it's a decorator, and is needed at definition-time
This commit is contained in:
parent
763399830d
commit
d01bfa6a72
1 changed files with 8 additions and 7 deletions
|
@ -200,6 +200,8 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_BOTO3 = False
|
HAS_BOTO3 = False
|
||||||
|
|
||||||
|
# import a class, otherwise we'll use a fully qualified path
|
||||||
|
from ansible.module_utils.ec2 import AWSRetry
|
||||||
|
|
||||||
def boto_exception(err):
|
def boto_exception(err):
|
||||||
'''generic error message handler'''
|
'''generic error message handler'''
|
||||||
|
@ -219,7 +221,7 @@ def boto_version_required(version_tuple):
|
||||||
try:
|
try:
|
||||||
for part in parts:
|
for part in parts:
|
||||||
boto_version.append(int(part))
|
boto_version.append(int(part))
|
||||||
except:
|
except ValueError:
|
||||||
boto_version.append(-1)
|
boto_version.append(-1)
|
||||||
return tuple(boto_version) >= tuple(version_tuple)
|
return tuple(boto_version) >= tuple(version_tuple)
|
||||||
|
|
||||||
|
@ -251,13 +253,14 @@ def get_stack_events(cfn, stack_name):
|
||||||
def stack_operation(cfn, stack_name, operation):
|
def stack_operation(cfn, stack_name, operation):
|
||||||
'''gets the status of a stack while it is created/updated/deleted'''
|
'''gets the status of a stack while it is created/updated/deleted'''
|
||||||
existed = []
|
existed = []
|
||||||
operation_complete = False
|
while True:
|
||||||
while operation_complete == False:
|
|
||||||
try:
|
try:
|
||||||
stack = get_stack_facts(cfn, stack_name)
|
stack = get_stack_facts(cfn, stack_name)
|
||||||
existed.append('yes')
|
existed.append('yes')
|
||||||
except:
|
except:
|
||||||
if 'yes' in existed or operation=='DELETE': # stacks may delete fast, look in a few ways.
|
# If the stack previously existed, and now can't be found then it's
|
||||||
|
# been deleted successfully.
|
||||||
|
if 'yes' in existed or operation == 'DELETE': # stacks may delete fast, look in a few ways.
|
||||||
ret = get_stack_events(cfn, stack_name)
|
ret = get_stack_events(cfn, stack_name)
|
||||||
ret.update({ 'changed': True, 'output': 'Stack Deleted'})
|
ret.update({ 'changed': True, 'output': 'Stack Deleted'})
|
||||||
return ret
|
return ret
|
||||||
|
@ -424,6 +427,7 @@ def main():
|
||||||
# don't need to be updated.
|
# don't need to be updated.
|
||||||
try:
|
try:
|
||||||
cfn.update_stack(**stack_params)
|
cfn.update_stack(**stack_params)
|
||||||
|
result = stack_operation(cfn, stack_params['StackName'], 'UPDATE')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
error_msg = boto_exception(err)
|
error_msg = boto_exception(err)
|
||||||
if 'No updates are to be performed.' in error_msg:
|
if 'No updates are to be performed.' in error_msg:
|
||||||
|
@ -432,7 +436,6 @@ def main():
|
||||||
module.fail_json(msg=error_msg)
|
module.fail_json(msg=error_msg)
|
||||||
#return {'error': error_msg}
|
#return {'error': error_msg}
|
||||||
#module.fail_json(msg=error_msg)
|
#module.fail_json(msg=error_msg)
|
||||||
result = stack_operation(cfn, stack_params['StackName'], 'UPDATE')
|
|
||||||
if not result: module.fail_json(msg="empty result")
|
if not result: module.fail_json(msg="empty result")
|
||||||
|
|
||||||
# check the status of the stack while we are creating/updating it.
|
# check the status of the stack while we are creating/updating it.
|
||||||
|
@ -478,8 +481,6 @@ def main():
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
import ansible.module_utils.ec2
|
import ansible.module_utils.ec2
|
||||||
|
|
||||||
# import a class, otherwise we'll use a fully qualified path
|
|
||||||
from ansible.module_utils.ec2 import AWSRetry
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue