Use playbook callbacks for adhoc commands too

This makes adhoc mirror playbook callback functionality by running a
callback before and after all tasks have run. Adhoc commands now call:

- v2_playbook_on_start
- v2_playbook_on_stats

NOTE: When v2_playbook_on_start is called, a dummy playbook is provided
that says its _file_name is __adhoc_playbook__. All callback plugins
that provide v2_playbook_on_start access the _file_name attribute, so
this should maintain backward compatibility when those plugins are
called with adhoc commands even though they would not have been called
previously. The adhoc play is also added to _entries for any private
callback plugins that might be using this callback.
pull/32469/head
Jacob Floyd 7 years ago committed by Brian Coca
parent f0e69c60fb
commit ca8668f08b

@ -28,6 +28,7 @@ from ansible.errors import AnsibleError, AnsibleOptionsError
from ansible.executor.task_queue_manager import TaskQueueManager from ansible.executor.task_queue_manager import TaskQueueManager
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.parsing.splitter import parse_kv from ansible.parsing.splitter import parse_kv
from ansible.playbook import Playbook
from ansible.playbook.play import Play from ansible.playbook.play import Play
from ansible.plugins.loader import get_all_plugin_loaders from ansible.plugins.loader import get_all_plugin_loaders
@ -145,6 +146,11 @@ 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)
# used in start callback
playbook = Playbook(loader)
playbook._entries.append(play)
playbook._file_name = '__adhoc_playbook__'
if self.callback: if self.callback:
cb = self.callback cb = self.callback
elif self.options.one_line: elif self.options.one_line:
@ -175,7 +181,11 @@ class AdHocCLI(CLI):
run_tree=run_tree, run_tree=run_tree,
) )
self._tqm.send_callback('v2_playbook_on_start', playbook)
result = self._tqm.run(play) result = self._tqm.run(play)
self._tqm.send_callback('v2_playbook_on_stats', self._tqm._stats)
finally: finally:
if self._tqm: if self._tqm:
self._tqm.cleanup() self._tqm.cleanup()

Loading…
Cancel
Save