perf(ops): ansible 增加 summary 汇总

pull/5592/head^2
ibuler 4 years ago committed by 老广
parent d795867916
commit 8f7dcd512a

@ -129,6 +129,9 @@ class AdHocResultCallback(CallbackMixin, CallbackModule, CMDCallBackModule):
self.gather_result("unreachable", result) self.gather_result("unreachable", result)
super().v2_runner_on_unreachable(result) super().v2_runner_on_unreachable(result)
def v2_runner_on_start(self, *args, **kwargs):
pass
def display_skipped_hosts(self): def display_skipped_hosts(self):
pass pass
@ -201,6 +204,9 @@ class CommandResultCallback(AdHocResultCallback):
msg, msg,
), color=C.COLOR_ERROR) ), color=C.COLOR_ERROR)
def v2_playbook_on_stats(self, stats):
pass
def _print_task_banner(self, task): def _print_task_banner(self, task):
pass pass

@ -6,6 +6,7 @@ import shutil
from collections import namedtuple from collections import namedtuple
from ansible import context from ansible import context
from ansible.playbook import Playbook
from ansible.module_utils.common.collections import ImmutableDict from ansible.module_utils.common.collections import ImmutableDict
from ansible.executor.task_queue_manager import TaskQueueManager from ansible.executor.task_queue_manager import TaskQueueManager
from ansible.vars.manager import VariableManager from ansible.vars.manager import VariableManager
@ -217,6 +218,11 @@ class AdHocRunner:
variable_manager=self.variable_manager, variable_manager=self.variable_manager,
loader=self.loader, loader=self.loader,
) )
loader = DataLoader()
# used in start callback
playbook = Playbook(loader)
playbook._entries.append(play)
playbook._file_name = '__adhoc_playbook__'
tqm = TaskQueueManager( tqm = TaskQueueManager(
inventory=self.inventory, inventory=self.inventory,
@ -226,7 +232,9 @@ class AdHocRunner:
passwords={"conn_pass": self.options.get("password", "")} passwords={"conn_pass": self.options.get("password", "")}
) )
try: try:
tqm.send_callback('v2_playbook_on_start', playbook)
tqm.run(play) tqm.run(play)
tqm.send_callback('v2_playbook_on_stats', tqm._stats)
return self.results_callback return self.results_callback
except Exception as e: except Exception as e:
raise AnsibleError(e) raise AnsibleError(e)

Loading…
Cancel
Save