Fix cloudformation module return parameter documentation

Always return stack outputs, even if only an empty dict
This commit is contained in:
Ryan S. Brown 2016-10-18 10:58:09 -04:00 committed by Matt Clay
commit 08b119df33

View file

@ -183,7 +183,11 @@ log:
"status_reason": null
}
]
stack_outputs:
type: dict
description: A key:value dictionary of all the stack outputs currently defined. If there are no stack outputs, it is an empty dictionary.
returned: always
sample: {"MySg": "AnsibleModuleTestYAML-CFTestSg-C8UVS567B6NS"}
'''
import json
@ -233,7 +237,7 @@ def get_stack_events(cfn, stack_name):
events = cfn.describe_stack_events(StackName=stack_name)
except (botocore.exceptions.ValidationError, botocore.exceptions.ClientError) as err:
error_msg = boto_exception(err)
if 'does not exist'.format(stack_name) in error_msg:
if 'does not exist' in error_msg:
# missing stack, don't bail.
ret['log'].append('Stack does not exist.')
return ret
@ -291,7 +295,6 @@ def stack_operation(cfn, stack_name, operation):
return ret
else:
# this can loop forever :/
#return dict(changed=True, failed=True, output = str(stack), operation=operation)
time.sleep(5)
return {'failed': True, 'output':'Failed for unknown reasons.'}
@ -356,7 +359,7 @@ def main():
mutually_exclusive=[['template_url', 'template']],
)
if not HAS_BOTO3:
module.fail_json(msg='boto3 required for this module')
module.fail_json(msg='boto3 and botocore are required for this module')
# collect the parameters that are passed to boto3. Keeps us from having so many scalars floating around.
stack_params = {
@ -443,6 +446,9 @@ def main():
if state == 'present' or update:
stack = get_stack_facts(cfn, stack_params['StackName'])
if result.get('stack_outputs') is None:
# always define stack_outputs, but it may be empty
result['stack_outputs'] = {}
for output in stack.get('Outputs', []):
result['stack_outputs'][output['OutputKey']] = output['OutputValue']
stack_resources = []
@ -467,7 +473,7 @@ def main():
try:
stack = get_stack_facts(cfn, stack_params['StackName'])
if not stack:
result = dict(changed=False, output='Stack not found.')
result = {'changed': False, 'output': 'Stack not found.'}
else:
cfn.delete_stack(StackName=stack_params['StackName'])
result = stack_operation(cfn, stack_params['StackName'], 'DELETE')