summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@ansible.com>2015-03-30 10:28:36 -0400
committerBrian Coca <bcoca@ansible.com>2015-03-30 10:28:36 -0400
commit3738339b90b3e8d0b285feefe73948e485649b26 (patch)
tree92cdb40965fd68b1e9885af71109d5baf7a17a2c
parentd27df0cdb4868ddea8956ab03ce398edc534017a (diff)
parentea1ffc6d196a6de2b8232c3473cc287f342629b4 (diff)
downloadansible-modules-core-3738339b90b3e8d0b285feefe73948e485649b26.tar.gz
Merge pull request #366 from Rob-Johnson/cloudformation-url
cloudformation: allow template_url parameter
-rw-r--r--cloud/amazon/cloudformation.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/cloud/amazon/cloudformation.py b/cloud/amazon/cloudformation.py
index 4253b63c..b25d7652 100644
--- a/cloud/amazon/cloudformation.py
+++ b/cloud/amazon/cloudformation.py
@@ -50,7 +50,7 @@ options:
aliases: []
template:
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
default: null
aliases: []
@@ -76,6 +76,11 @@ options:
default: null
aliases: ['aws_region', 'ec2_region']
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
extends_documentation_fragment: aws
@@ -105,6 +110,21 @@ tasks:
cloudformation:
stack_name: "ansible-cloudformation-old"
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
@@ -200,33 +220,42 @@ def main():
template=dict(default=None, required=False),
stack_policy=dict(default=None, required=False),
disable_rollback=dict(default=False, type='bool'),
+ template_url=dict(default=None, required=False),
tags=dict(default=None)
)
)
module = AnsibleModule(
argument_spec=argument_spec,
+ mutually_exclusive=[['template_url', 'template']],
)
if not HAS_BOTO:
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']
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:
template_body = open(module.params['template'], 'r').read()
else:
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:
stack_policy_body = open(module.params['stack_policy'], 'r').read()
else:
stack_policy_body = None
+
disable_rollback = module.params['disable_rollback']
template_parameters = module.params['template_parameters']
tags = module.params['tags']
+ template_url = module.params['template_url']
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,
template_body=template_body,
stack_policy_body=stack_policy_body,
+ template_url=template_url,
disable_rollback=disable_rollback,
capabilities=['CAPABILITY_IAM'],
**kwargs)
@@ -281,6 +311,7 @@ def main():
template_body=template_body,
stack_policy_body=stack_policy_body,
disable_rollback=disable_rollback,
+ template_url=template_url,
capabilities=['CAPABILITY_IAM'])
operation = 'UPDATE'
except Exception, err: