def playbook_on_stats()

in playbooks/callback_plugins/hipchat_plugin.py [0:0]


    def playbook_on_stats(self, stats):
        if self.enabled:
            self._flush_last_task()
            delta = time.time() - self.start_time
            self.start_time = time.time()
            """Display info about playbook statistics"""
            hosts = sorted(stats.processed.keys())
            task_column = '{} - Task'.format(self.hipchat_msg_prefix)
            task_summary = prettytable.PrettyTable([task_column, 'Time', 'Count', 'Changed'])
            task_summary.align[task_column] = "l"
            task_summary.align['Time'] = "r"
            task_summary.align['Count'] = "r"
            task_summary.align['Changed'] = "r"



            for task in self.task_report:
                if self.condensed_task_report:
                    # for the condensed task report skip all tasks
                    # that are not marked as changed and that have
                    # a time delta less than 1
                    if not task['changed'] and float(task['delta']) < 1:
                        continue
                task_summary.add_row([task['task'], task['delta'], str(task['count']), str(task['changed'])])

            summary_table = prettytable.PrettyTable(['Ok', 'Changed', 'Unreachable', 'Failures'])
            self._send_hipchat("/code " + str(task_summary) )

            summary_all_host_output = []
            for host in hosts:
                stats = stats.summarize(host)
                summary_output = "<b>{}</b>: <i>{}</i> - ".format(self.hipchat_msg_prefix, host)
                for summary_item in ['ok', 'changed', 'unreachable', 'failures']:
                    if stats[summary_item] != 0:
                        summary_output += "<b>{}</b> - {} ".format(summary_item, stats[summary_item])
                summary_all_host_output.append(summary_output)
            self._send_hipchat("<br />".join(summary_all_host_output), message_format='html')
            msg = "<b>{description}</b>: Finished Ansible run for <b><i>{play}</i> in {min:02} minutes, {sec:02} seconds</b><br /><br />".format(
                description=self.hipchat_msg_prefix,
                play=self.playbook_name,
                min=int(delta / 60),
                sec=int(delta % 60))
            self._send_hipchat(msg, message_format='html')