mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Fix cloudformation module return parameter documentation
Always return stack outputs, even if only an empty dict
This commit is contained in:
parent
d01bfa6a72
commit
08b119df33
1 changed files with 34 additions and 28 deletions
|
@ -183,7 +183,11 @@ log:
|
||||||
"status_reason": null
|
"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
|
import json
|
||||||
|
@ -233,7 +237,7 @@ def get_stack_events(cfn, stack_name):
|
||||||
events = cfn.describe_stack_events(StackName=stack_name)
|
events = cfn.describe_stack_events(StackName=stack_name)
|
||||||
except (botocore.exceptions.ValidationError, botocore.exceptions.ClientError) as err:
|
except (botocore.exceptions.ValidationError, botocore.exceptions.ClientError) as err:
|
||||||
error_msg = boto_exception(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.
|
# missing stack, don't bail.
|
||||||
ret['log'].append('Stack does not exist.')
|
ret['log'].append('Stack does not exist.')
|
||||||
return ret
|
return ret
|
||||||
|
@ -291,7 +295,6 @@ def stack_operation(cfn, stack_name, operation):
|
||||||
return ret
|
return ret
|
||||||
else:
|
else:
|
||||||
# this can loop forever :/
|
# this can loop forever :/
|
||||||
#return dict(changed=True, failed=True, output = str(stack), operation=operation)
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
return {'failed': True, 'output':'Failed for unknown reasons.'}
|
return {'failed': True, 'output':'Failed for unknown reasons.'}
|
||||||
|
|
||||||
|
@ -356,7 +359,7 @@ def main():
|
||||||
mutually_exclusive=[['template_url', 'template']],
|
mutually_exclusive=[['template_url', 'template']],
|
||||||
)
|
)
|
||||||
if not HAS_BOTO3:
|
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.
|
# collect the parameters that are passed to boto3. Keeps us from having so many scalars floating around.
|
||||||
stack_params = {
|
stack_params = {
|
||||||
|
@ -443,6 +446,9 @@ def main():
|
||||||
|
|
||||||
if state == 'present' or update:
|
if state == 'present' or update:
|
||||||
stack = get_stack_facts(cfn, stack_params['StackName'])
|
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', []):
|
for output in stack.get('Outputs', []):
|
||||||
result['stack_outputs'][output['OutputKey']] = output['OutputValue']
|
result['stack_outputs'][output['OutputKey']] = output['OutputValue']
|
||||||
stack_resources = []
|
stack_resources = []
|
||||||
|
@ -467,7 +473,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
stack = get_stack_facts(cfn, stack_params['StackName'])
|
stack = get_stack_facts(cfn, stack_params['StackName'])
|
||||||
if not stack:
|
if not stack:
|
||||||
result = dict(changed=False, output='Stack not found.')
|
result = {'changed': False, 'output': 'Stack not found.'}
|
||||||
else:
|
else:
|
||||||
cfn.delete_stack(StackName=stack_params['StackName'])
|
cfn.delete_stack(StackName=stack_params['StackName'])
|
||||||
result = stack_operation(cfn, stack_params['StackName'], 'DELETE')
|
result = stack_operation(cfn, stack_params['StackName'], 'DELETE')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue