Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom callbacks with adhoc cli #13498

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ansible/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CLI(object):
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)

def __init__(self, args):
def __init__(self, args, callback=None):
"""
Base init method for all command line programs
"""
Expand All @@ -75,6 +75,7 @@ def __init__(self, args):
self.options = None
self.parser = None
self.action = None
self.callback = callback

def set_action(self):
"""
Expand Down
4 changes: 3 additions & 1 deletion lib/ansible/cli/adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def run(self):
play_ds = self._play_ds(pattern, self.options.seconds, self.options.poll_interval)
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'
else:
cb = 'minimal'
Expand Down
11 changes: 9 additions & 2 deletions lib/ansible/executor/task_queue_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from ansible.plugins import callback_loader, strategy_loader, module_loader
from ansible.template import Templar
from ansible.vars.hostvars import HostVars
from ansible.plugins.callback import CallbackBase

try:
from __main__ import display
Expand Down Expand Up @@ -146,8 +147,14 @@ def load_callbacks(self):
if self._stdout_callback is None:
self._stdout_callback = C.DEFAULT_STDOUT_CALLBACK

if self._stdout_callback not in callback_loader:
raise AnsibleError("Invalid callback for stdout specified: %s" % self._stdout_callback)
if isinstance(self._stdout_callback, CallbackBase):
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):
if hasattr(callback_plugin, 'CALLBACK_VERSION') and callback_plugin.CALLBACK_VERSION >= 2.0:
Expand Down