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.
... | ... |
@@ -328,13 +328,6 @@ class Runner(object): |
328 | 328 |
def _executor_internal_inner(self, host, module_name, module_args, inject, port, is_chained=False): |
329 | 329 |
''' decides how to invoke a module ''' |
330 | 330 |
|
331 |
- # special non-user/non-fact variables: |
|
332 |
- # 'groups' variable is a list of host name in each group |
|
333 |
- # 'hostvars' variable contains variables for each host name |
|
334 |
- # ... and is set elsewhere |
|
335 |
- # 'inventory_hostname' is also set elsewhere |
|
336 |
- inject['groups'] = self.inventory.groups_list() |
|
337 |
- |
|
338 | 331 |
# allow module args to work as a dictionary |
339 | 332 |
# though it is usually a string |
340 | 333 |
new_args = "" |
... | ... |
@@ -343,6 +336,18 @@ class Runner(object): |
343 | 343 |
new_args = new_args + "%s='%s' " % (k,v) |
344 | 344 |
module_args = new_args |
345 | 345 |
|
346 |
+ module_name = utils.template(self.basedir, module_name, inject) |
|
347 |
+ module_args = utils.template(self.basedir, module_args, inject, expand_lists=True) |
|
348 |
+ |
|
349 |
+ if module_name in utils.plugins.action_loader: |
|
350 |
+ if self.background != 0: |
|
351 |
+ raise errors.AnsibleError("async mode is not supported with the %s module" % module_name) |
|
352 |
+ handler = utils.plugins.action_loader.get(module_name, self) |
|
353 |
+ elif self.background == 0: |
|
354 |
+ handler = utils.plugins.action_loader.get('normal', self) |
|
355 |
+ else: |
|
356 |
+ handler = utils.plugins.action_loader.get('async', self) |
|
357 |
+ |
|
346 | 358 |
conditional = utils.template(self.basedir, self.conditional, inject) |
347 | 359 |
if not utils.check_conditional(conditional): |
348 | 360 |
result = utils.jsonify(dict(skipped=True)) |
... | ... |
@@ -396,24 +401,12 @@ class Runner(object): |
396 | 396 |
result = dict(failed=True, msg="FAILED: %s" % str(e)) |
397 | 397 |
return ReturnData(host=host, comm_ok=False, result=result) |
398 | 398 |
|
399 |
- module_name = utils.template(self.basedir, module_name, inject) |
|
400 |
- module_args = utils.template(self.basedir, module_args, inject, expand_lists=True) |
|
401 |
- |
|
402 | 399 |
tmp = '' |
403 |
- if self.module_name != 'raw': |
|
400 |
+ # all modules get a tempdir, action plugins get one unless they have NEEDS_TMPPATH set to False |
|
401 |
+ if getattr(handler, 'NEEDS_TMPPATH', True): |
|
404 | 402 |
tmp = self._make_tmp_path(conn) |
405 |
- result = None |
|
406 | 403 |
|
407 |
- if module_name in utils.plugins.action_loader: |
|
408 |
- if self.background != 0: |
|
409 |
- raise errors.AnsibleError("async mode is not supported with the %s module" % module_name) |
|
410 |
- handler = utils.plugins.action_loader.get(module_name, self) |
|
411 |
- result = handler.run(conn, tmp, module_name, module_args, inject) |
|
412 |
- else: |
|
413 |
- if self.background == 0: |
|
414 |
- result = utils.plugins.action_loader.get('normal', self).run(conn, tmp, module_name, module_args, inject) |
|
415 |
- else: |
|
416 |
- result = utils.plugins.action_loader.get('async', self).run(conn, tmp, module_name, module_args, inject) |
|
404 |
+ result = handler.run(conn, tmp, module_name, module_args, inject) |
|
417 | 405 |
|
418 | 406 |
conn.close() |
419 | 407 |
|