From 8f7dcd512a0ed67774b8efe6b7e44b5380f76681 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 19 Feb 2021 10:50:52 +0800 Subject: [PATCH] =?UTF-8?q?perf(ops):=20ansible=20=E5=A2=9E=E5=8A=A0=20sum?= =?UTF-8?q?mary=20=E6=B1=87=E6=80=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/ansible/callback.py | 6 ++++++ apps/ops/ansible/runner.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/apps/ops/ansible/callback.py b/apps/ops/ansible/callback.py index 8edbbbcb7..3264e59c2 100644 --- a/apps/ops/ansible/callback.py +++ b/apps/ops/ansible/callback.py @@ -129,6 +129,9 @@ class AdHocResultCallback(CallbackMixin, CallbackModule, CMDCallBackModule): self.gather_result("unreachable", result) super().v2_runner_on_unreachable(result) + def v2_runner_on_start(self, *args, **kwargs): + pass + def display_skipped_hosts(self): pass @@ -201,6 +204,9 @@ class CommandResultCallback(AdHocResultCallback): msg, ), color=C.COLOR_ERROR) + def v2_playbook_on_stats(self, stats): + pass + def _print_task_banner(self, task): pass diff --git a/apps/ops/ansible/runner.py b/apps/ops/ansible/runner.py index fdbed74cb..a25d681b9 100644 --- a/apps/ops/ansible/runner.py +++ b/apps/ops/ansible/runner.py @@ -6,6 +6,7 @@ import shutil from collections import namedtuple from ansible import context +from ansible.playbook import Playbook from ansible.module_utils.common.collections import ImmutableDict from ansible.executor.task_queue_manager import TaskQueueManager from ansible.vars.manager import VariableManager @@ -217,6 +218,11 @@ class AdHocRunner: variable_manager=self.variable_manager, loader=self.loader, ) + loader = DataLoader() + # used in start callback + playbook = Playbook(loader) + playbook._entries.append(play) + playbook._file_name = '__adhoc_playbook__' tqm = TaskQueueManager( inventory=self.inventory, @@ -226,7 +232,9 @@ class AdHocRunner: passwords={"conn_pass": self.options.get("password", "")} ) try: + tqm.send_callback('v2_playbook_on_start', playbook) tqm.run(play) + tqm.send_callback('v2_playbook_on_stats', tqm._stats) return self.results_callback except Exception as e: raise AnsibleError(e)