allow custom callbacks with adhoc cli for scripting
missing import of CallbackBase
This commit is contained in:
parent
30e729557f
commit
6680cc7052
3 changed files with 14 additions and 4 deletions
|
@ -66,7 +66,7 @@ class CLI(object):
|
||||||
LESS_OPTS = 'FRSX' # -F (quit-if-one-screen) -R (allow raw ansi control chars)
|
LESS_OPTS = 'FRSX' # -F (quit-if-one-screen) -R (allow raw ansi control chars)
|
||||||
# -S (chop long lines) -X (disable termcap init and de-init)
|
# -S (chop long lines) -X (disable termcap init and de-init)
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args, callback=None):
|
||||||
"""
|
"""
|
||||||
Base init method for all command line programs
|
Base init method for all command line programs
|
||||||
"""
|
"""
|
||||||
|
@ -75,6 +75,7 @@ class CLI(object):
|
||||||
self.options = None
|
self.options = None
|
||||||
self.parser = None
|
self.parser = None
|
||||||
self.action = None
|
self.action = None
|
||||||
|
self.callback = callback
|
||||||
|
|
||||||
def set_action(self):
|
def set_action(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -158,7 +158,9 @@ class AdHocCLI(CLI):
|
||||||
play_ds = self._play_ds(pattern, self.options.seconds, self.options.poll_interval)
|
play_ds = self._play_ds(pattern, self.options.seconds, self.options.poll_interval)
|
||||||
play = Play().load(play_ds, variable_manager=variable_manager, loader=loader)
|
play = Play().load(play_ds, variable_manager=variable_manager, loader=loader)
|
||||||
|
|
||||||
if self.options.one_line:
|
if self.callback:
|
||||||
|
cb = self.callback
|
||||||
|
elif self.options.one_line:
|
||||||
cb = 'oneline'
|
cb = 'oneline'
|
||||||
else:
|
else:
|
||||||
cb = 'minimal'
|
cb = 'minimal'
|
||||||
|
|
|
@ -34,6 +34,7 @@ from ansible.playbook.play_context import PlayContext
|
||||||
from ansible.plugins import callback_loader, strategy_loader, module_loader
|
from ansible.plugins import callback_loader, strategy_loader, module_loader
|
||||||
from ansible.template import Templar
|
from ansible.template import Templar
|
||||||
from ansible.vars.hostvars import HostVars
|
from ansible.vars.hostvars import HostVars
|
||||||
|
from ansible.plugins.callback import CallbackBase
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from __main__ import display
|
from __main__ import display
|
||||||
|
@ -146,8 +147,14 @@ class TaskQueueManager:
|
||||||
if self._stdout_callback is None:
|
if self._stdout_callback is None:
|
||||||
self._stdout_callback = C.DEFAULT_STDOUT_CALLBACK
|
self._stdout_callback = C.DEFAULT_STDOUT_CALLBACK
|
||||||
|
|
||||||
if self._stdout_callback not in callback_loader:
|
if isinstance(self._stdout_callback, CallbackBase):
|
||||||
raise AnsibleError("Invalid callback for stdout specified: %s" % self._stdout_callback)
|
self._callback_plugins.append(self._stdout_callback)
|
||||||
|
stdout_callback_loaded = True
|
||||||
|
elif isinstance(self._stdout_callback, basestring):
|
||||||
|
if self._stdout_callback not in callback_loader:
|
||||||
|
raise AnsibleError("Invalid callback for stdout specified: %s" % self._stdout_callback)
|
||||||
|
else:
|
||||||
|
raise AnsibleError("callback must be an instance of CallbackBase or the name of a callback plugin")
|
||||||
|
|
||||||
for callback_plugin in callback_loader.all(class_only=True):
|
for callback_plugin in callback_loader.all(class_only=True):
|
||||||
if hasattr(callback_plugin, 'CALLBACK_VERSION') and callback_plugin.CALLBACK_VERSION >= 2.0:
|
if hasattr(callback_plugin, 'CALLBACK_VERSION') and callback_plugin.CALLBACK_VERSION >= 2.0:
|
||||||
|
|
Loading…
Reference in a new issue