Fix the incompatibility for ansible 2.1.0

Ansible 2.1.0 has lots of change and the plugin is not compatible
between 2.0.0 and 2.1.0. This change fix the gap.

* fix the signature change for _make_tmp_path in ansible 2.1.0
* fix the common_options in the kolla_docker.py

Change-Id: I05f5f05581c8bd625cd868fa0db549d0c60a7043
Closes-Bug: #1586018
This commit is contained in:
Jeffrey Zhang 2016-05-27 01:04:03 +08:00
parent b40bf517ae
commit 3545e6d503
2 changed files with 14 additions and 14 deletions

View File

@ -16,6 +16,7 @@
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from cStringIO import StringIO from cStringIO import StringIO
import inspect
import os import os
from ansible.plugins.action import ActionBase from ansible.plugins.action import ActionBase
@ -41,8 +42,16 @@ class ActionModule(ActionBase):
task_vars = dict() task_vars = dict()
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
if not tmp: # NOTE(jeffrey4l): Ansible 2.1 add a remote_user param to the
# _make_tmp_path function. inspect the number of the args here. In
# this way, ansible 2.0 and ansible 2.1 are both supported
make_tmp_path_args = inspect.getargspec(self._make_tmp_path)[0]
if not tmp and len(make_tmp_path_args) == 1:
tmp = self._make_tmp_path() tmp = self._make_tmp_path()
if not tmp and len(make_tmp_path_args) == 2:
remote_user = (task_vars.get('ansible_ssh_user')
or self._play_context.remote_user)
tmp = self._make_tmp_path(remote_user)
sources = self._task.args.get('sources', None) sources = self._task.args.get('sources', None)
extra_vars = self._task.args.get('vars', list()) extra_vars = self._task.args.get('vars', list())

View File

@ -681,17 +681,12 @@ def generate_module():
required_together = [ required_together = [
['tls_cert', 'tls_key'] ['tls_cert', 'tls_key']
] ]
return AnsibleModule( module = AnsibleModule(
argument_spec=argument_spec, argument_spec=argument_spec,
required_together=required_together, required_together=required_together,
bypass_checks=True bypass_checks=True
) )
def generate_nested_module():
module = generate_module()
# We unnest the common dict and the update it with the other options
new_args = module.params.pop('common_options', dict()) new_args = module.params.pop('common_options', dict())
# NOTE(jeffrey4l): merge the environment # NOTE(jeffrey4l): merge the environment
@ -704,16 +699,12 @@ def generate_nested_module():
continue continue
new_args[key] = value new_args[key] = value
# Override ARGS to ensure new args are used module.params = new_args
global MODULE_COMPLEX_ARGS return module
MODULE_COMPLEX_ARGS = json.dumps(new_args)
# Reprocess the args now that the common dict has been unnested
return generate_module()
def main(): def main():
module = generate_nested_module() module = generate_module()
# TODO(SamYaple): Replace with required_if when Ansible 2.0 lands # TODO(SamYaple): Replace with required_if when Ansible 2.0 lands
if (module.params.get('action') in ['pull_image', 'start_container'] if (module.params.get('action') in ['pull_image', 'start_container']