diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 7837e691a9..b12033ac73 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -328,13 +328,6 @@ class Runner(object): def _executor_internal_inner(self, host, module_name, module_args, inject, port, is_chained=False): ''' decides how to invoke a module ''' - # special non-user/non-fact variables: - # 'groups' variable is a list of host name in each group - # 'hostvars' variable contains variables for each host name - # ... and is set elsewhere - # 'inventory_hostname' is also set elsewhere - inject['groups'] = self.inventory.groups_list() - # allow module args to work as a dictionary # though it is usually a string new_args = "" @@ -343,6 +336,18 @@ class Runner(object): new_args = new_args + "%s='%s' " % (k,v) module_args = new_args + module_name = utils.template(self.basedir, module_name, inject) + module_args = utils.template(self.basedir, module_args, inject, expand_lists=True) + + if module_name in utils.plugins.action_loader: + if self.background != 0: + raise errors.AnsibleError("async mode is not supported with the %s module" % module_name) + handler = utils.plugins.action_loader.get(module_name, self) + elif self.background == 0: + handler = utils.plugins.action_loader.get('normal', self) + else: + handler = utils.plugins.action_loader.get('async', self) + conditional = utils.template(self.basedir, self.conditional, inject) if not utils.check_conditional(conditional): result = utils.jsonify(dict(skipped=True)) @@ -396,24 +401,12 @@ class Runner(object): result = dict(failed=True, msg="FAILED: %s" % str(e)) return ReturnData(host=host, comm_ok=False, result=result) - module_name = utils.template(self.basedir, module_name, inject) - module_args = utils.template(self.basedir, module_args, inject, expand_lists=True) - tmp = '' - if self.module_name != 'raw': + # all modules get a tempdir, action plugins get one unless they have NEEDS_TMPPATH set to False + if getattr(handler, 'NEEDS_TMPPATH', True): tmp = self._make_tmp_path(conn) - result = None - if module_name in utils.plugins.action_loader: - if self.background != 0: - raise errors.AnsibleError("async mode is not supported with the %s module" % module_name) - handler = utils.plugins.action_loader.get(module_name, self) - result = handler.run(conn, tmp, module_name, module_args, inject) - else: - if self.background == 0: - result = utils.plugins.action_loader.get('normal', self).run(conn, tmp, module_name, module_args, inject) - else: - result = utils.plugins.action_loader.get('async', self).run(conn, tmp, module_name, module_args, inject) + result = handler.run(conn, tmp, module_name, module_args, inject) conn.close() diff --git a/lib/ansible/runner/action_plugins/add_host.py b/lib/ansible/runner/action_plugins/add_host.py index 5b3aed8120..f2ce7ccfe9 100644 --- a/lib/ansible/runner/action_plugins/add_host.py +++ b/lib/ansible/runner/action_plugins/add_host.py @@ -29,6 +29,7 @@ class ActionModule(object): ### We need to be able to modify the inventory BYPASS_HOST_LOOP = True + NEEDS_TMPPATH = False def __init__(self, runner): self.runner = runner diff --git a/lib/ansible/runner/action_plugins/debug.py b/lib/ansible/runner/action_plugins/debug.py index 5f862add82..e25d9c2739 100644 --- a/lib/ansible/runner/action_plugins/debug.py +++ b/lib/ansible/runner/action_plugins/debug.py @@ -23,6 +23,8 @@ from ansible.runner.return_data import ReturnData class ActionModule(object): ''' Print statements during execution ''' + NEEDS_TMPPATH = False + def __init__(self, runner): self.runner = runner diff --git a/lib/ansible/runner/action_plugins/fail.py b/lib/ansible/runner/action_plugins/fail.py index c28c1bb2b0..f835a1f493 100644 --- a/lib/ansible/runner/action_plugins/fail.py +++ b/lib/ansible/runner/action_plugins/fail.py @@ -23,6 +23,8 @@ from ansible.runner.return_data import ReturnData class ActionModule(object): ''' Fail with custom message ''' + NEEDS_TMPPATH = False + def __init__(self, runner): self.runner = runner diff --git a/lib/ansible/runner/action_plugins/group_by.py b/lib/ansible/runner/action_plugins/group_by.py index 35c39d226b..7e8a6d563b 100644 --- a/lib/ansible/runner/action_plugins/group_by.py +++ b/lib/ansible/runner/action_plugins/group_by.py @@ -27,6 +27,7 @@ class ActionModule(object): ### We need to be able to modify the inventory BYPASS_HOST_LOOP = True + NEEDS_TMPPATH = False def __init__(self, runner): self.runner = runner diff --git a/lib/ansible/runner/action_plugins/raw.py b/lib/ansible/runner/action_plugins/raw.py index 64eaefdaa2..3e4dca7605 100644 --- a/lib/ansible/runner/action_plugins/raw.py +++ b/lib/ansible/runner/action_plugins/raw.py @@ -28,6 +28,7 @@ from ansible import module_common from ansible.runner.return_data import ReturnData class ActionModule(object): + NEEDS_TMPPATH = False def __init__(self, runner): self.runner = runner