From bda08c8a1b501e0a1ca2d4898b869fa9eca8ef95 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Wed, 28 Nov 2012 16:22:35 +0100 Subject: [PATCH] Avoid creating temporary directory for some action plugins This ensures we don't litter remote systems with temporary directories that don't get cleaned up, as well as speeds things up from not having to touch every node. --- lib/ansible/runner/__init__.py | 37 ++++++++----------- lib/ansible/runner/action_plugins/add_host.py | 1 + lib/ansible/runner/action_plugins/debug.py | 2 + lib/ansible/runner/action_plugins/fail.py | 2 + lib/ansible/runner/action_plugins/group_by.py | 1 + lib/ansible/runner/action_plugins/raw.py | 1 + 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 7837e691a97..b12033ac731 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 5b3aed8120c..f2ce7ccfe95 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 5f862add827..e25d9c27397 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 c28c1bb2b0e..f835a1f493f 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 35c39d226ba..7e8a6d563b6 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 64eaefdaa27..3e4dca7605f 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