1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

allow both template and template_url parameters

This commit is contained in:
Rob Johnson 2014-11-20 16:18:54 +00:00 committed by Matt Clay
parent f88f895795
commit d8af3f3b67

View file

@ -50,7 +50,7 @@ options:
aliases: [] aliases: []
template: template:
description: description:
- The path of the cloudformation template, required if state is "present". - The local path of the cloudformation template. This parameter is mutually exclusive with 'template_url'. Either one of them is required if "state" parameter is "present"
required: false required: false
default: null default: null
aliases: [] aliases: []
@ -76,6 +76,11 @@ options:
default: null default: null
aliases: ['aws_region', 'ec2_region'] aliases: ['aws_region', 'ec2_region']
version_added: "1.5" version_added: "1.5"
template_url:
description:
- 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"
author: James S. Martin author: James S. Martin
extends_documentation_fragment: aws extends_documentation_fragment: aws
@ -105,6 +110,21 @@ tasks:
cloudformation: cloudformation:
stack_name: "ansible-cloudformation-old" stack_name: "ansible-cloudformation-old"
state: "absent" state: "absent"
# Use a template from a URL
tasks:
- name: launch ansible cloudformation example
cloudformation:
stack_name="ansible-cloudformation" state=present
region=us-east-1 disable_rollback=true
template_url=https://s3.amazonaws.com/my-bucket/cloudformation.template
args:
template_parameters:
KeyName: jmartin
DiskType: ephemeral
InstanceType: m1.small
ClusterSize: 3
tags:
Stack: ansible-cloudformation
''' '''
import json import json
@ -200,33 +220,42 @@ def main():
template=dict(default=None, required=False), template=dict(default=None, required=False),
stack_policy=dict(default=None, required=False), stack_policy=dict(default=None, required=False),
disable_rollback=dict(default=False, type='bool'), disable_rollback=dict(default=False, type='bool'),
template_url=dict(default=None, required=False),
tags=dict(default=None) tags=dict(default=None)
) )
) )
module = AnsibleModule( module = AnsibleModule(
argument_spec=argument_spec, argument_spec=argument_spec,
mutually_exclusive=[['template_url', 'template']],
) )
if not HAS_BOTO: if not HAS_BOTO:
module.fail_json(msg='boto required for this module') module.fail_json(msg='boto required for this module')
if module.params['template'] is None and module.params['template_url'] is None:
module.fail_json(msg='Either template or template_url expected')
state = module.params['state'] state = module.params['state']
stack_name = module.params['stack_name'] stack_name = module.params['stack_name']
if module.params['template'] is None and module.params['template_url'] is None:
if state == 'present':
module.fail_json('Module parameter "template" or "template_url" is required if "state" is "present"')
if module.params['template'] is not None: if module.params['template'] is not None:
template_body = open(module.params['template'], 'r').read() template_body = open(module.params['template'], 'r').read()
else: else:
template_body = None template_body = None
if state == 'present':
module.fail_json('Module parameter "template" is required if "state" is "present"')
if module.params['stack_policy'] is not None: if module.params['stack_policy'] is not None:
stack_policy_body = open(module.params['stack_policy'], 'r').read() stack_policy_body = open(module.params['stack_policy'], 'r').read()
else: else:
stack_policy_body = None stack_policy_body = None
disable_rollback = module.params['disable_rollback'] disable_rollback = module.params['disable_rollback']
template_parameters = module.params['template_parameters'] template_parameters = module.params['template_parameters']
tags = module.params['tags'] tags = module.params['tags']
template_url = module.params['template_url']
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
@ -259,6 +288,7 @@ def main():
cfn.create_stack(stack_name, parameters=template_parameters_tup, cfn.create_stack(stack_name, parameters=template_parameters_tup,
template_body=template_body, template_body=template_body,
stack_policy_body=stack_policy_body, stack_policy_body=stack_policy_body,
template_url=template_url,
disable_rollback=disable_rollback, disable_rollback=disable_rollback,
capabilities=['CAPABILITY_IAM'], capabilities=['CAPABILITY_IAM'],
**kwargs) **kwargs)
@ -281,6 +311,7 @@ def main():
template_body=template_body, template_body=template_body,
stack_policy_body=stack_policy_body, stack_policy_body=stack_policy_body,
disable_rollback=disable_rollback, disable_rollback=disable_rollback,
template_url=template_url,
capabilities=['CAPABILITY_IAM']) capabilities=['CAPABILITY_IAM'])
operation = 'UPDATE' operation = 'UPDATE'
except Exception, err: except Exception, err: