mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cloudformation: accept local templates in yaml format
Since the YAML data format is a subset of JSON, it is trivial to convert the former to the latter. This means that we can use YAML templates to build cloudformation stacks, as long as we translate them before passing them to the AWS API. I figure this could potentially be quite popular in the Ansible world, since we already use so much YAML for our playbooks.
This commit is contained in:
parent
38d0f31cac
commit
ff7dfefbd6
1 changed files with 14 additions and 0 deletions
|
@ -81,6 +81,12 @@ options:
|
|||
- Location of file containing the template body. The URL must point to a template (max size 307,200 bytes) located in an S3 bucket in the same region as the stack. This parameter is mutually exclusive with 'template'. Either one of them is required if "state" parameter is "present"
|
||||
required: false
|
||||
version_added: "2.0"
|
||||
template_format:
|
||||
description: For local templates, allows specification of json or yaml format
|
||||
default: json
|
||||
choices: [ json, yaml ]
|
||||
required: false
|
||||
version_added: "2.0"
|
||||
|
||||
author: James S. Martin
|
||||
extends_documentation_fragment: aws
|
||||
|
@ -127,6 +133,7 @@ EXAMPLES = '''
|
|||
|
||||
import json
|
||||
import time
|
||||
import yaml
|
||||
|
||||
try:
|
||||
import boto
|
||||
|
@ -224,6 +231,7 @@ def main():
|
|||
stack_policy=dict(default=None, required=False),
|
||||
disable_rollback=dict(default=False, type='bool'),
|
||||
template_url=dict(default=None, required=False),
|
||||
template_format=dict(default='json', choices=['json', 'yaml'], required=False),
|
||||
tags=dict(default=None)
|
||||
)
|
||||
)
|
||||
|
@ -250,6 +258,12 @@ def main():
|
|||
else:
|
||||
template_body = None
|
||||
|
||||
if module.params['template_format'] == 'yaml':
|
||||
if template_body is None:
|
||||
module.fail_json(msg='yaml format only supported for local templates')
|
||||
else:
|
||||
template_body = json.dumps(yaml.load(template_body), indent=2)
|
||||
|
||||
if module.params['stack_policy'] is not None:
|
||||
stack_policy_body = open(module.params['stack_policy'], 'r').read()
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue