mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add Boto version check for tags parameter of cloudformation module
Tags parameter requires at least version 2.6.0 of Boto module. When tags parameter is used with older version, error is raised. When tags parameter is unused, module works as before.
This commit is contained in:
parent
b5ae761070
commit
d294669dec
1 changed files with 19 additions and 1 deletions
|
@ -63,6 +63,7 @@ options:
|
||||||
tags:
|
tags:
|
||||||
description:
|
description:
|
||||||
- Dictionary of tags to associate with stack and it's resources during stack creation. Cannot be updated later.
|
- Dictionary of tags to associate with stack and it's resources during stack creation. Cannot be updated later.
|
||||||
|
Requires at least Boto version 2.6.0.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
|
@ -93,6 +94,7 @@ import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import boto
|
||||||
import boto.cloudformation.connection
|
import boto.cloudformation.connection
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "failed=True msg='boto required for this module'"
|
print "failed=True msg='boto required for this module'"
|
||||||
|
@ -126,6 +128,17 @@ def boto_exception(err):
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
|
||||||
|
def boto_version_required(version_tuple):
|
||||||
|
parts = boto.Version.split('.')
|
||||||
|
boto_version = []
|
||||||
|
try:
|
||||||
|
for part in parts:
|
||||||
|
boto_version.append(int(part))
|
||||||
|
except:
|
||||||
|
boto_version.append(-1)
|
||||||
|
return tuple(boto_version) >= tuple(version_tuple)
|
||||||
|
|
||||||
|
|
||||||
def stack_operation(cfn, stack_name, operation):
|
def stack_operation(cfn, stack_name, operation):
|
||||||
'''gets the status of a stack while it is created/updated/deleted'''
|
'''gets the status of a stack while it is created/updated/deleted'''
|
||||||
existed = []
|
existed = []
|
||||||
|
@ -190,6 +203,11 @@ def main():
|
||||||
elif 'EC2_REGION' in os.environ:
|
elif 'EC2_REGION' in os.environ:
|
||||||
r = os.environ['EC2_REGION']
|
r = os.environ['EC2_REGION']
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
if tags is not None:
|
||||||
|
if not boto_version_required((2,6,0)):
|
||||||
|
module.fail_json(msg='Module parameter "tags" requires at least Boto version 2.6.0')
|
||||||
|
kwargs['tags'] = tags
|
||||||
|
|
||||||
|
|
||||||
# convert the template parameters ansible passes into a tuple for boto
|
# convert the template parameters ansible passes into a tuple for boto
|
||||||
|
@ -214,7 +232,7 @@ def main():
|
||||||
template_body=template_body,
|
template_body=template_body,
|
||||||
disable_rollback=disable_rollback,
|
disable_rollback=disable_rollback,
|
||||||
capabilities=['CAPABILITY_IAM'],
|
capabilities=['CAPABILITY_IAM'],
|
||||||
tags=tags)
|
**kwargs)
|
||||||
operation = 'CREATE'
|
operation = 'CREATE'
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
error_msg = boto_exception(err)
|
error_msg = boto_exception(err)
|
||||||
|
|
Loading…
Reference in a new issue