mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix typo that breaks invocation of os_stack (#56575)
* Fix typo that breaks invocation of os_stack * Apply tags conditionally so that the module does not throw up an error when using an older distro of openstacksdk
This commit is contained in:
parent
6c1a255d98
commit
18f22de67e
1 changed files with 18 additions and 20 deletions
|
@ -154,16 +154,15 @@ from ansible.module_utils.openstack import openstack_full_argument_spec, opensta
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
def _create_stack(module, stack, cloud, sdk):
|
def _create_stack(module, stack, cloud, sdk, parameters):
|
||||||
try:
|
try:
|
||||||
stack = cloud.create_stack(module.params['name'],
|
stack = cloud.create_stack(module.params['name'],
|
||||||
tags=module.params['tag'],
|
|
||||||
template_file=module.params['template'],
|
template_file=module.params['template'],
|
||||||
environment_files=module.params['environment'],
|
environment_files=module.params['environment'],
|
||||||
timeout=module.params['timeout'],
|
timeout=module.params['timeout'],
|
||||||
wait=True,
|
wait=True,
|
||||||
rollback=module.params['rollback'],
|
rollback=module.params['rollback'],
|
||||||
**module.params['parameters'])
|
**parameters)
|
||||||
|
|
||||||
stack = cloud.get_stack(stack.id, None)
|
stack = cloud.get_stack(stack.id, None)
|
||||||
if stack.stack_status == 'CREATE_COMPLETE':
|
if stack.stack_status == 'CREATE_COMPLETE':
|
||||||
|
@ -177,17 +176,16 @@ def _create_stack(module, stack, cloud, sdk):
|
||||||
module.fail_json(msg=to_native(e))
|
module.fail_json(msg=to_native(e))
|
||||||
|
|
||||||
|
|
||||||
def _update_stack(module, stack, cloud, sdk):
|
def _update_stack(module, stack, cloud, sdk, parameters):
|
||||||
try:
|
try:
|
||||||
stack = cloud.update_stack(
|
stack = cloud.update_stack(
|
||||||
module.params['name'],
|
module.params['name'],
|
||||||
tags=module.params['tag'],
|
|
||||||
template_file=module.params['template'],
|
template_file=module.params['template'],
|
||||||
environment_files=module.params['environment'],
|
environment_files=module.params['environment'],
|
||||||
timeout=module.params['timeout'],
|
timeout=module.params['timeout'],
|
||||||
rollback=module.params['rollback'],
|
rollback=module.params['rollback'],
|
||||||
wait=module.params['wait'],
|
wait=module.params['wait'],
|
||||||
**module.params['parameters'])
|
**parameters)
|
||||||
|
|
||||||
if stack['stack_status'] == 'UPDATE_COMPLETE':
|
if stack['stack_status'] == 'UPDATE_COMPLETE':
|
||||||
return stack
|
return stack
|
||||||
|
@ -242,24 +240,24 @@ def main():
|
||||||
stack = cloud.get_stack(name)
|
stack = cloud.get_stack(name)
|
||||||
|
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
module.exit_json(changed=_system_state_change(module, stack,
|
module.exit_json(changed=_system_state_change(module, stack, cloud))
|
||||||
cloud))
|
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
parameters = module.params['parameters']
|
||||||
|
if module.params['tag']:
|
||||||
|
parameters['tags'] = module.params['tag']
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
min_version = '0.28.0'
|
||||||
|
if StrictVersion(sdk.version.__version__) < StrictVersion(min_version) and stack:
|
||||||
|
module.warn("To update tags using os_stack module, the"
|
||||||
|
"installed version of the openstacksdk"
|
||||||
|
"library MUST be >={min_version}"
|
||||||
|
"".format(min_version=min_version))
|
||||||
if not stack:
|
if not stack:
|
||||||
stack = _create_stack(module, stack, cloud, sdk)
|
stack = _create_stack(module, stack, cloud, sdk, parameters)
|
||||||
else:
|
else:
|
||||||
if module.params['tags']:
|
stack = _update_stack(module, stack, cloud, sdk, parameters)
|
||||||
from distutils.version import StrictVersion
|
module.exit_json(changed=True,
|
||||||
min_version = '0.28.0'
|
|
||||||
if StrictVersion(sdk.version.__version__) < StrictVersion(min_version):
|
|
||||||
module.warn("To update tags using os_stack module, the"
|
|
||||||
"installed version of the openstacksdk"
|
|
||||||
"library MUST be >={min_version}"
|
|
||||||
"".format(min_version=min_version))
|
|
||||||
stack = _update_stack(module, stack, cloud, sdk)
|
|
||||||
changed = True
|
|
||||||
module.exit_json(changed=changed,
|
|
||||||
stack=stack,
|
stack=stack,
|
||||||
id=stack.id)
|
id=stack.id)
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
|
|
Loading…
Reference in a new issue