Two fixes to action plugins

* Fix the task_vars parameter to not default to a mutable type (dict)
* Implement invocation in the base class's run() method have each action
  module call the run() method's implemention in the base class.
* Return values from the action plugins' run() method takes the return
  value from the base class run() method into account so that invocation
  makes its way to the output.

Fixes #12869
This commit is contained in:
Toshio Kuratomi 2015-10-22 16:07:26 -07:00
parent 75cff7129c
commit 2e87c1f74e
27 changed files with 387 additions and 179 deletions

View file

@ -17,18 +17,20 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.plugins.action import ActionBase
class ActionModule(ActionBase):
TRANSFERS_FILES = False
def run(self, tmp=None, task_vars=dict()):
def run(self, tmp=None, task_vars=None):
''' handler for package operations '''
if task_vars is None:
task_vars = dict()
result = super(ActionModule, self).run(tmp, task_vars)
name = self._task.args.get('name', None)
state = self._task.args.get('state', None)
module = self._task.args.get('use', 'auto')
if module == 'auto':
@ -40,13 +42,15 @@ class ActionModule(ActionBase):
if module == 'auto':
facts = self._execute_module(module_name='setup', module_args=dict(filter='ansible_pkg_mgr'), task_vars=task_vars)
self._display.debug("Facts %s" % facts)
if not 'failed' in facts:
if 'failed' not in facts:
module = getattr(facts['ansible_facts'], 'ansible_pkg_mgr', 'auto')
if module != 'auto':
if module not in self._shared_loader_obj.module_loader:
return {'failed': True, 'msg': 'Could not find a module for %s.' % module}
result['failed'] = True
result['msg'] = 'Could not find a module for %s.' % module
return result
# run the 'package' module
new_module_args = self._task.args.copy()
@ -54,8 +58,9 @@ class ActionModule(ActionBase):
del new_module_args['use']
self._display.vvvv("Running %s" % module)
return self._execute_module(module_name=module, module_args=new_module_args, task_vars=task_vars)
result.update(self._execute_module(module_name=module, module_args=new_module_args, task_vars=task_vars))
return result
else:
return {'failed': True, 'msg': 'Could not detect which package manager to use. Try gathering facts or setting the "use" option.'}
result['failed'] = True
result['msg'] = 'Could not detect which package manager to use. Try gathering facts or setting the "use" option.'
return result