From 242b04b4fe2d1fae3f67d84e05bff7c405ccef02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toshio=20=E3=81=8F=E3=82=89=E3=81=A8=E3=81=BF?= Date: Sat, 30 Jan 2016 05:57:06 +0000 Subject: [PATCH] Some attributes have moved to other objects in v2 --- callback_plugins/fedmsg_callback2.py | 24 ++++++++++++--------- callback_plugins/logdetail2.py | 31 +++++++++++++++++++--------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/callback_plugins/fedmsg_callback2.py b/callback_plugins/fedmsg_callback2.py index e2ba924d7f..a2399d0415 100644 --- a/callback_plugins/fedmsg_callback2.py +++ b/callback_plugins/fedmsg_callback2.py @@ -28,6 +28,11 @@ except ImportError: # Ansible v1 compat CallbackBase = object +try: + from ansible.utils.hashing import secure_hash +except ImportError: + from ansible.utils import md5 as secure_hash + def getlogin(): try: user = os.getlogin() @@ -65,22 +70,21 @@ class CallbackModule(CallbackBase): super(CallbackModule, self).__init__() + def set_play_context(self, play_context): + self.play_context = play_context + def v2_playbook_on_start(self, playbook): self.playbook = playbook - import q ; q.q(playbook) - import q ; q.q(dir(playbook)) def v2_playbook_on_play_start(self, play): # This gets called once for each play.. but we just issue a message once # for the first one. One per "playbook" - import q ; q.q(play) - import q ; q.q(dir(play)) if self.playbook: # figure out where the playbook FILE is - path = os.path.abspath(self.playbook.filename) + path = os.path.abspath(self.playbook._file_name) # Bail out early without publishing if we're in --check mode - if self.playbook.check: + if self.play_context.check_mode: return if not self.playbook_path: @@ -89,10 +93,10 @@ class CallbackModule(CallbackBase): msg=dict( playbook=path, userid=getlogin(), - extra_vars=self.playbook.extra_vars, - inventory=self.playbook.inventory.host_list, - playbook_checksum=self.playbook.check, - check=self.playbook.check, + extra_vars=play.vars.extra_vars, + inventory=play.vars._inventory.src(), + playbook_checksum=secure_hash(path), + check=self.play_context.check_mode, ), ) self.playbook_path = path diff --git a/callback_plugins/logdetail2.py b/callback_plugins/logdetail2.py index 1d1170a9a6..4de7022328 100644 --- a/callback_plugins/logdetail2.py +++ b/callback_plugins/logdetail2.py @@ -19,7 +19,11 @@ import os import time import json import pwd -from ansible import utils + +try: + from ansible.utils.hashing import secure_hash +except ImportError: + from ansible.utils import md5 as secure_hash try: from ansible.plugins.callback import CallbackBase @@ -171,9 +175,13 @@ class CallbackModule(CallbackBase): self._task_count = 0 self._play_count = 0 self.task = None + self.playbook = None super(CallbackModule, self).__init__() + def set_play_context(self, play_context): + self.play_context = play_context + def runner_on_failed(self, result, ignore_errors=False): category = 'FAILED' logmech.log(result._host.get_name(), category, result._result, self.task, self._task_count) @@ -198,6 +206,9 @@ class CallbackModule(CallbackBase): category = 'ASYNC_FAILED' logmech.log(result._host.get_name(), category, result._result, self.task, self._task_count) + def v2_playbook_on_start(self, playbook): + self.playbook = playbook + def v2_playbook_on_task_start(self, task, is_conditional): self.task = task logmech._last_task_start = time.time() @@ -221,7 +232,7 @@ class CallbackModule(CallbackBase): if play: # figure out where the playbook FILE is - path = os.path.abspath(play.playbook.filename) + path = os.path.abspath(self.playbook._file_name) # tel the logger what the playbook is logmech.playbook_id = path @@ -233,11 +244,11 @@ class CallbackModule(CallbackBase): pb_info['playbook_start'] = time.time() pb_info['playbook'] = path pb_info['userid'] = getlogin() - pb_info['extra_vars'] = play.playbook.extra_vars - pb_info['inventory'] = play.playbook.inventory.host_list - pb_info['playbook_checksum'] = utils.md5(path) - pb_info['check'] = play.playbook.check - pb_info['diff'] = play.playbook.diff + pb_info['extra_vars'] = play.vars.extra_vars + pb_info['inventory'] = play.vars._inventory.src() + pb_info['playbook_checksum'] = secure_hash(path) + pb_info['check'] = self.play_context.check_mode + pb_info['diff'] = self.play_context.diff logmech.play_log(json.dumps(pb_info, indent=4)) self._play_count += 1 @@ -245,10 +256,10 @@ class CallbackModule(CallbackBase): info = {} info['play'] = play.name info['hosts'] = play.hosts - info['transport'] = play.transport + info['transport'] = self.play_context.connection info['number'] = self._play_count - info['check'] = play.playbook.check - info['diff'] = play.playbook.diff + info['check'] = self.play_context.check_mode + info['diff'] = self.play_context.diff logmech.play_info = info logmech.play_log(json.dumps(info, indent=4))