mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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.
This commit is contained in:
parent
f6e7381a71
commit
bda08c8a1b
6 changed files with 22 additions and 22 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue