def v2_playbook_on_stats(self, stats): if self._display.verbosity == 0 and self.keep: sys.stdout.write(vt100.restore + vt100.reset + '\n' + vt100.save + vt100.clearline) else: sys.stdout.write(vt100.restore + vt100.reset + vt100.clearline) # In normal mode screen output should be sufficient, summary is redundant if self._display.verbosity == 0: return sys.stdout.write(vt100.bold + vt100.underline) sys.stdout.write('SUMMARY') sys.stdout.write(vt100.restore + vt100.reset + '\n' + vt100.save + vt100.clearline) sys.stdout.flush() hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True)
def v2_playbook_on_stats(self, stats): if self._display.verbosity == 0 and self.keep: sys.stdout.write(vt100.restore + vt100.reset + '\n' + vt100.save + vt100.clearline) else: sys.stdout.write(vt100.restore + vt100.reset + vt100.clearline) # In normal mode screen output should be sufficient, summary is redundant if self._display.verbosity == 0: return sys.stdout.write(vt100.bold + vt100.underline) sys.stdout.write('SUMMARY') sys.stdout.write(vt100.restore + vt100.reset + '\n' + vt100.save + vt100.clearline) sys.stdout.flush() hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True )
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") state = [] hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True) state.append({ u"host": h, u'ok': t['ok'], u'changed': t['changed'], u'unreachable': t['unreachable'], u'failed': t['failures'] }) if len(stats.failures) > 0: self.mongo.update(track_id=self.track_id, data={ "state": state, "status": 'ok' }) else: self.mongo.update(track_id=self.track_id, data={ "state": state, "status": 'failed' })
def v2_playbook_on_stats(self, stats): print("{}[{}] | PLAYBOOK SUMMARY {}{}\n".format( '\033[34m', str(datetime.datetime.now()), ">" * 31, '\033[37m', )) hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], 'purple'), colorize(u'changed', t['changed'], 'blue'), colorize(u'unreachable', t['unreachable'], 'red'), colorize(u'failed', t['failures'], 'red')), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], 'green'), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): print("[{}] | PLAYBOOK SUMMARY {}\n".format( str(datetime.datetime.now()), ">" * 31)) hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR), colorize(u'skipped', t['skipped'], C.COLOR_SKIP)), screen_only=True) self._display.display( u"%s : %s %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None), colorize(u'skipped', t['skipped'], None)), log_only=True) self._display.display("", screen_only=True) # print custom stats if required if stats.custom and self.show_custom_stats: self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display( '\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results( stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True) if self._playbook and self._playbook._executor and self._playbook._executor._options.check: self._display.banner("DRY RUN (no changes were made)")
def v2_playbook_on_stats(self, stats): summarized = dict(ok=[], changed=[], unreachable=[], failures=[]) hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) for i, v in t.items(): summarized.setdefault(i, []).append(v) self._display.banner("SUMMARY: ") self._display.display( u"%s %s %s %s" % (colorize(u'ok', sum(summarized['ok']), C.COLOR_OK), colorize(u'changed', sum(summarized['changed']), C.COLOR_CHANGED), colorize(u'unreachable', sum(summarized['unreachable']), C.COLOR_UNREACHABLE), colorize(u'failed', sum(summarized['failures']), C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s %s %s %s" % (colorize(u'ok', sum(summarized['ok']), None), colorize(u'changed', sum(summarized['changed']), None), colorize(u'unreachable', sum(summarized['unreachable']), None), colorize(u'failed', sum(summarized['failures']), None)), log_only=True) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._open_section("system") self._emit_line("-- Play recap --") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._emit_line( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], UNCHANGED), colorize(u'changed', t['changed'], CHANGED), colorize(u'unreachable', t['unreachable'], CHANGED), colorize(u'failed', t['failures'], 'red')))
def v2_playbook_on_stats(self, stats): self._display.banner("TEST RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) # NOTE: Make fail if one or more test results were changed=True if t['changed'] > 0 and t['failures'] == 0: t['failures'] = 1 self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True ) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True ) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._open_section("system") self._emit_line("-- Play recap --") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._emit_line(u"%s : %s %s %s %s" % ( hostcolor(h, t), colorize(u"ok", t["ok"], UNCHANGED), colorize(u"changed", t["changed"], CHANGED), colorize(u"unreachable", t["unreachable"], CHANGED), colorize(u"failed", t["failures"], "red"), ))
def v2_playbook_on_stats(self, stats): self._output_general("-- Summary -- [ {} -> {} ]".format( self.play_started_fmt, ("%ds" % self._get_play_duration()).ljust(self.ms_len)), color=COLOUR_EXTRA) hosts = sorted(stats.processed.keys()) for host in hosts: totals = stats.summarize(host) self._output_general(u" {} : {} {} {} {}".format( hostcolor(host, totals), colorize(u'ok', totals['ok'], COLOUR_OK), colorize(u'changed', totals['changed'], COLOUR_CHANGED), colorize(u'unreachable', totals['unreachable'], COLOUR_UNREACHABLE), colorize(u'failed', totals['failures'], COLOUR_FAILED)))
def v2_playbook_on_stats(self, stats): self._display.banner("Summary") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s %s" % (hostcolor(h, t), colorize(u'Ok', t['ok'], C.COLOR_OK), colorize(u'Changed', t['changed'], C.COLOR_CHANGED), colorize(u'Unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'Failed', t['failures'], C.COLOR_ERROR), colorize(u'Skipped', t['skipped'], C.COLOR_SKIP)), screen_only=True) self._display.display( u"%s : %s %s %s %s %s" % (hostcolor(h, t, False), colorize(u'Ok', t['ok'], None), colorize(u'Changed', t['changed'], None), colorize(u'Unreachable', t['unreachable'], None), colorize(u'Failed', t['failures'], None), colorize(u'Skip', t['skipped'], None)), log_only=True) self._display.display("", screen_only=True) # print custom stats if required if stats.custom and self.show_custom_stats: self._display.banner("Custom stats: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display( '\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRun: %s' % self._dump_results( stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._display.banner("Summary") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display(u"%s : %s %s %s %s %s" % ( hostcolor(h, t), colorize(u'Ok', t['ok'], C.COLOR_OK), colorize(u'Changed', t['changed'], C.COLOR_CHANGED), colorize(u'Unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'Failed', t['failures'], C.COLOR_ERROR), colorize(u'Skipped', t['skipped'], C.COLOR_SKIP)), screen_only=True ) self._display.display(u"%s : %s %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'Ok', t['ok'], None), colorize(u'Changed', t['changed'], None), colorize(u'Unreachable', t['unreachable'], None), colorize(u'Failed', t['failures'], None), colorize(u'Skip', t['skipped'], None)), log_only=True ) self._display.display("", screen_only=True) # print custom stats if required if stats.custom and self.show_custom_stats: self._display.banner("Custom stats: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display('\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace('\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRun: %s' % self._dump_results(stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): #-------------------------------------# # Begin custom progress display print # if self._prev_carried_msg is not None: # print blank line so last carried messages are not overwritten by command prompt self._clear_carried_msg() self.progress_display('') # End custom progress display print # #-----------------------------------# self._display.banner("PLAY RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True) # print custom stats if required if stats.custom and self.show_custom_stats: self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display( '\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results( stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True)
def _prints_report(self): coverage_color = C.COLOR_ERROR unreachable_color = coverage_color if self.total_tasks == self.executed_tasks: coverage_color = C.COLOR_OK unreachable_color = None num_unreachable_tasks = self.total_tasks-self.executed_tasks self._display.banner('COVERAGE') self._prints_calls() self._display.display(u"%-26s : %s %s %s %s" % ( self.playbook_name, colorize(u'coverage', '%.0f' % self.coverage, coverage_color), colorize(u'ok', self.total_tasks, C.COLOR_OK), colorize(u'changed', self.executed_tasks, C.COLOR_CHANGED), colorize(u'unreachable', num_unreachable_tasks, unreachable_color) ), screen_only=True) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): if self.playbook_failure: subject = 'Ansible: [Playbook failed] Post failure recap' body = 'Error(s) occurred for host(s) in playbook!\n\n____PLAY RECAP____\n' hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) body += "%s : %s %s %s %s\n" % ( hostcolor(h, t, False), colorize('ok', t['ok'], None), colorize('changed', t['changed'], None), colorize('unreachable', t['unreachable'], None), colorize('failed', t['failures'], None)) self.playbook_failure = False self.mail(subject=subject, body=body)
def v2_playbook_on_stats(self, stats): hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) if t['unreachable'] > 0 or t['failures'] > 0: self._display.banner("PLAY RECAP") self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), screen_only=True ) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): if self._total_results is not None: print( json.dumps( {"servers": list(self._total_results.values())}, indent=4, sort_keys=True, )) self._display.display("MACHINE STATS RECAP", stderr=True) hosts = sorted(stats.processed.keys()) for h in hosts: # pylint: disable=invalid-name t = stats.summarize(h) # pylint: disable=invalid-name self._display.display( u"%s : %s %s %s %s %s %s %s" % ( hostcolor(h, t), colorize(u"ok", t["ok"], C.COLOR_OK), # pylint: disable=no-member colorize( u"changed", t["changed"], C.COLOR_CHANGED, # pylint: disable=no-member ), colorize( u"unreachable", t["unreachable"], C.COLOR_UNREACHABLE, # pylint: disable=no-member ), colorize( u"failed", t["failures"], C.COLOR_ERROR, # pylint: disable=no-member ), colorize( u"skipped", t["skipped"], C.COLOR_SKIP, # pylint: disable=no-member ), colorize( u"rescued", t["rescued"], C.COLOR_OK, # pylint: disable=no-member ), colorize( u"ignored", t["ignored"], C.COLOR_WARN, # pylint: disable=no-member ), ), screen_only=True, stderr=True, ) self._display.display("", screen_only=True, stderr=True)
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") hosts = sorted(stats.processed.keys()) for host in hosts: stat = stats.summarize(host) self._display.display( u"%s : %s %s %s %s" % (hostcolor(host, stat), colorize(u'ok', stat['ok'], C.COLOR_OK), colorize(u'changed', stat['changed'], C.COLOR_CHANGED), colorize(u'unreachable', stat['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', stat['failures'], C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(host, stat, False), colorize( u'ok', stat['ok'], None), colorize(u'changed', stat['changed'], None), colorize(u'unreachable', stat['unreachable'], None), colorize(u'failed', stat['failures'], None)), log_only=True) self._display.display("", screen_only=True) # print custom stats if self._plugin_options.get('show_custom_stats', C.SHOW_CUSTOM_STATS) and stats.custom: # fallback on constants for inherited plugins missing docs self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display( '\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results( stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True ) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True ) self._display.display("", screen_only=True) # print custom stats if self._plugin_options.get('show_custom_stats', C.SHOW_CUSTOM_STATS) and stats.custom: # fallback on constants for inherited plugins missing docs self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display('\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace('\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results(stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): """Print the final playbook run stats""" self._display.display("", screen_only=True) self.banner("PLAY RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True ) self._display.display( u"%s : %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True ) self._display.display("", screen_only=True) self._display.display("", screen_only=True) # Some plays are conditional and won't run (such as load # balancers) if they aren't required. Sometimes plays are # conditionally included later in the run. Let the user know # about this to avoid potential confusion. if self.plays_total_ran != self.plays_count: print("Installation Complete: Note: Play count is only an estimate, some plays may have been skipped or dynamically added") self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): """Print the final playbook run stats""" self._display.display("", screen_only=True) self.banner("PLAY RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True ) self._display.display( u"%s : %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True ) self._display.display("", screen_only=True) self._display.display("", screen_only=True) # Some plays are conditional and won't run (such as load # balancers) if they aren't required. Let the user know about # this to avoid potential confusion. if self.plays_total_ran != self.plays_count: print("Installation Complete: Note: Play count is an estimate and some were skipped because your install does not require them") self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._display.banner("PLAYGG RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display(u"%s : %s %s %s %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR), colorize(u'skipped', t['skipped'], C.COLOR_SKIP), colorize(u'rescued', t['rescued'], C.COLOR_OK), colorize(u'ignored', t['ignored'], C.COLOR_WARN), ), screen_only=True) self._display.display(u"%s : %s %s %s %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None), colorize(u'skipped', t['skipped'], None), colorize(u'rescued', t['rescued'], None), colorize(u'ignored', t['ignored'], None), ), log_only=True) self._display.display("", screen_only=True) summary = {} for h in hosts: s = stats.summarize(h) summary[h] = s custom_stats = {} global_custom_stats = {} # print custom stats if required if stats.custom and self.show_custom_stats: self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display( '\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results( stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True) custom_stats.update( dict((self._convert_host_to_name(k), v) for k, v in stats.custom.items())) global_custom_stats.update(custom_stats.pop('_run', {})) output = { 'plays': self.results, 'stats': summary, 'custom_stats': custom_stats, 'global_custom_stats': global_custom_stats, } if environ.get('ANSIBLE_JSON_LOG_FILE') is not None: with open(environ.get('ANSIBLE_JSON_LOG_FILE'), 'w') as outfile: json.dump(output, outfile) if environ.get('ANSIBLE_JSON_LOG_DEBUG') is not None: self._display.display( json.dumps(output, cls=AnsibleJSONEncoder, indent=4, sort_keys=True))
def run(self): ''' Run the given playbook, based on the settings in the play which may limit the runs to serialized groups, etc. ''' signal.signal(signal.SIGINT, self._cleanup) result = 0 entrylist = [] entry = {} try: for playbook_path in self._playbooks: pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader) self._inventory.set_playbook_basedir(os.path.dirname(playbook_path)) if self._tqm is None: # we are doing a listing entry = {'playbook': playbook_path} entry['plays'] = [] i = 1 plays = pb.get_plays() self._display.vv('%d plays in %s' % (len(plays), playbook_path)) for play in plays: if play._included_path is not None: self._loader.set_basedir(play._included_path) else: self._loader.set_basedir(pb._basedir) # clear any filters which may have been applied to the inventory self._inventory.remove_restriction() if play.vars_prompt: for var in play.vars_prompt: vname = var['name'] prompt = var.get("prompt", vname) default = var.get("default", None) private = var.get("private", True) confirm = var.get("confirm", False) encrypt = var.get("encrypt", None) salt_size = var.get("salt_size", None) salt = var.get("salt", None) if vname not in play.vars: if self._tqm: self._tqm.send_callback('v2_playbook_on_vars_prompt', vname, private, prompt, encrypt, confirm, salt_size, salt, default) play.vars[vname] = self._do_var_prompt(vname, private, prompt, encrypt, confirm, salt_size, salt, default) # Create a temporary copy of the play here, so we can run post_validate # on it without the templating changes affecting the original object. all_vars = self._variable_manager.get_vars(loader=self._loader, play=play) templar = Templar(loader=self._loader, variables=all_vars) new_play = play.copy() new_play.post_validate(templar) if self._options.syntax: continue if self._tqm is None: # we are just doing a listing entry['plays'].append(new_play) else: # make sure the tqm has callbacks loaded self._tqm.load_callbacks() self._tqm._unreachable_hosts.update(self._unreachable_hosts) # we are actually running plays for batch in self._get_serialized_batches(new_play): if len(batch) == 0: self._tqm.send_callback('v2_playbook_on_play_start', new_play) self._tqm.send_callback('v2_playbook_on_no_hosts_matched') break # restrict the inventory to the hosts in the serialized batch self._inventory.restrict_to_hosts(batch) # and run it... result = self._tqm.run(play=play) # check the number of failures here, to see if they're above the maximum # failure percentage allowed, or if any errors are fatal. If either of those # conditions are met, we break out, otherwise we only break out if the entire # batch failed failed_hosts_count = len(self._tqm._failed_hosts) + len(self._tqm._unreachable_hosts) if new_play.any_errors_fatal and failed_hosts_count > 0: break elif new_play.max_fail_percentage is not None and \ int((new_play.max_fail_percentage)/100.0 * len(batch)) > int((len(batch) - failed_hosts_count) / len(batch) * 100.0): break elif len(batch) == failed_hosts_count: break # clear the failed hosts dictionaires in the TQM for the next batch self._unreachable_hosts.update(self._tqm._unreachable_hosts) self._tqm.clear_failed_hosts() # if the last result wasn't zero or 3 (some hosts were unreachable), # break out of the serial batch loop if result not in (0, 3): break i = i + 1 # per play if entry: entrylist.append(entry) # per playbook # if the last result wasn't zero, break out of the playbook file name loop if result != 0: break if entrylist: return entrylist finally: if self._tqm is not None: self._cleanup() if self._options.syntax: self.display.display("No issues encountered") return result # FIXME: this stat summary stuff should be cleaned up and moved # to a new method, if it even belongs here... self._display.banner("PLAY RECAP") hosts = sorted(self._tqm._stats.processed.keys()) for h in hosts: t = self._tqm._stats.summarize(h) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], 'green'), colorize(u'changed', t['changed'], 'yellow'), colorize(u'unreachable', t['unreachable'], 'red'), colorize(u'failed', t['failures'], 'red')), screen_only=True ) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True ) self._display.display("", screen_only=True) # END STATS STUFF return result
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") summarized = dict(ok=[], changed=[], unreachable=[], failures=[]) hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) for i, v in t.items(): summarized.setdefault(i, []).append(v) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True) self._display.banner("SUMMARY: ") self._display.display( u"%s %s %s %s" % (colorize(u'ok', sum(summarized['ok']), C.COLOR_OK), colorize(u'changed', sum(summarized['changed']), C.COLOR_CHANGED), colorize(u'unreachable', sum(summarized['unreachable']), C.COLOR_UNREACHABLE), colorize(u'failed', sum(summarized['failures']), C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s %s %s %s" % (colorize(u'ok', sum(summarized['ok']), None), colorize(u'changed', sum(summarized['changed']), None), colorize(u'unreachable', sum(summarized['unreachable']), None), colorize(u'failed', sum(summarized['failures']), None)), log_only=True) self._display.display("", screen_only=True) # print custom stats if required if stats.custom and self.show_custom_stats: self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display( '\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results( stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True)
def run(self): ''' Run the given playbook, based on the settings in the play which may limit the runs to serialized groups, etc. ''' signal.signal(signal.SIGINT, self._cleanup) result = 0 entrylist = [] entry = {} try: for playbook_path in self._playbooks: pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader) self._inventory.set_playbook_basedir( os.path.dirname(playbook_path)) if self._tqm is None: # we are doing a listing entry = {'playbook': playbook_path} entry['plays'] = [] i = 1 plays = pb.get_plays() self._display.vv('%d plays in %s' % (len(plays), playbook_path)) for play in plays: if play._included_path is not None: self._loader.set_basedir(play._included_path) # clear any filters which may have been applied to the inventory self._inventory.remove_restriction() if play.vars_prompt: for var in play.vars_prompt: vname = var['name'] prompt = var.get("prompt", vname) default = var.get("default", None) private = var.get("private", True) confirm = var.get("confirm", False) encrypt = var.get("encrypt", None) salt_size = var.get("salt_size", None) salt = var.get("salt", None) if vname not in play.vars: if self._tqm: self._tqm.send_callback( 'v2_playbook_on_vars_prompt', vname, private, prompt, encrypt, confirm, salt_size, salt, default) play.vars[vname] = self._do_var_prompt( vname, private, prompt, encrypt, confirm, salt_size, salt, default) # Create a temporary copy of the play here, so we can run post_validate # on it without the templating changes affecting the original object. all_vars = self._variable_manager.get_vars( loader=self._loader, play=play) templar = Templar(loader=self._loader, variables=all_vars) new_play = play.copy() new_play.post_validate(templar) if self._options.syntax: continue if self._tqm is None: # we are just doing a listing entry['plays'].append(new_play) else: # make sure the tqm has callbacks loaded self._tqm.load_callbacks() self._tqm._unreachable_hosts.update( self._unreachable_hosts) # we are actually running plays for batch in self._get_serialized_batches(new_play): if len(batch) == 0: self._tqm.send_callback( 'v2_playbook_on_play_start', new_play) self._tqm.send_callback( 'v2_playbook_on_no_hosts_matched') break # restrict the inventory to the hosts in the serialized batch self._inventory.restrict_to_hosts(batch) # and run it... result = self._tqm.run(play=play) # check the number of failures here, to see if they're above the maximum # failure percentage allowed, or if any errors are fatal. If either of those # conditions are met, we break out, otherwise we only break out if the entire # batch failed failed_hosts_count = len( self._tqm._failed_hosts) + len( self._tqm._unreachable_hosts) if new_play.any_errors_fatal and failed_hosts_count > 0: break elif new_play.max_fail_percentage is not None and \ int((new_play.max_fail_percentage)/100.0 * len(batch)) > int((len(batch) - failed_hosts_count) / len(batch) * 100.0): break elif len(batch) == failed_hosts_count: break # clear the failed hosts dictionaires in the TQM for the next batch self._unreachable_hosts.update( self._tqm._unreachable_hosts) self._tqm.clear_failed_hosts() # if the last result wasn't zero or 3 (some hosts were unreachable), # break out of the serial batch loop if result not in (0, 3): break i = i + 1 # per play if entry: entrylist.append(entry) # per playbook # if the last result wasn't zero, break out of the playbook file name loop if result != 0: break if entrylist: return entrylist finally: if self._tqm is not None: self._cleanup() if self._options.syntax: self.display.display("No issues encountered") return result # FIXME: this stat summary stuff should be cleaned up and moved # to a new method, if it even belongs here... self._display.banner("PLAY RECAP") hosts = sorted(self._tqm._stats.processed.keys()) for h in hosts: t = self._tqm._stats.summarize(h) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], 'green'), colorize(u'changed', t['changed'], 'yellow'), colorize(u'unreachable', t['unreachable'], 'red'), colorize(u'failed', t['failures'], 'red')), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True) # END STATS STUFF return result
def v2_playbook_on_stats(self, stats): output = "" hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) output += u"%s : %s %s %s %s %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR), colorize(u'skipped', t['skipped'], C.COLOR_SKIP), colorize(u'rescued', t['rescued'], C.COLOR_OK), colorize(u'ignored', t['ignored'], C.COLOR_WARN), self.carriage_return) self._display.display(u"%s : %s %s %s %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None), colorize(u'skipped', t['skipped'], None), colorize(u'rescued', t['rescued'], None), colorize(u'ignored', t['ignored'], None), ), log_only=True) # print custom stats if required if False: # if stats.custom: # and self.show_custom_stats: self.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue output += "\t%s: %s %s" % ( k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''), self.carriage_return) # print per run custom stats if '_run' in stats.custom: output += self.carriage_return output += "\tRUN: %s %s" % (self._dump_results( stats.custom['_run'], indent=1).replace( '\n', ''), self.carriage_return) output += self.carriage_return table_data = [ [output], ] statsTable = AsciiTable(table_data) statsTable.title = "Play Recap" self._display.display("") self._display.display(statsTable.table, screen_only=True) self._display.display("")
def run(self): ''' Run the given playbook, based on the settings in the play which may limit the runs to serialized groups, etc. ''' signal.signal(signal.SIGINT, self._cleanup) result = 0 entrylist = [] entry = {} try: for playbook_path in self._playbooks: pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader) if self._tqm is None: # we are doing a listing entry = {'playbook': playbook_path} entry['plays'] = [] i = 1 plays = pb.get_plays() self._display.vv('%d plays in %s' % (len(plays), playbook_path)) for play in plays: self._inventory.remove_restriction() # Create a temporary copy of the play here, so we can run post_validate # on it without the templating changes affecting the original object. all_vars = self._variable_manager.get_vars( loader=self._loader, play=play) new_play = play.copy() new_play.post_validate(all_vars, fail_on_undefined=False) if self._tqm is None: # we are just doing a listing pname = new_play.get_name().strip() if pname == 'PLAY: <no name specified>': pname = 'PLAY: #%d' % i p = {'name': pname} if self._options.listhosts: p['pattern'] = play.hosts p['hosts'] = set( self._inventory.get_hosts(new_play.hosts)) #TODO: play tasks are really blocks, need to figure out how to get task objects from them elif self._options.listtasks: p['tasks'] = [] for task in play.get_tasks(): p['tasks'].append(task) #p['tasks'].append({'name': task.get_name().strip(), 'tags': task.tags}) elif self._options.listtags: p['tags'] = set(new_play.tags) for task in play.get_tasks(): p['tags'].update(task) #p['tags'].update(task.tags) entry['plays'].append(p) else: # we are actually running plays for batch in self._get_serialized_batches(new_play): if len(batch) == 0: self._tqm.send_callback( 'v2_playbook_on_play_start', new_play) self._tqm.send_callback( 'v2_playbook_on_no_hosts_matched') result = 0 break # restrict the inventory to the hosts in the serialized batch self._inventory.restrict_to_hosts(batch) # and run it... result = self._tqm.run(play=play) if result != 0: break if result != 0: break i = i + 1 # per play if entry: entrylist.append(entry) # per playbook if entrylist: return entrylist finally: if self._tqm is not None: self._cleanup() # FIXME: this stat summary stuff should be cleaned up and moved # to a new method, if it even belongs here... self._display.banner("PLAY RECAP") hosts = sorted(self._tqm._stats.processed.keys()) for h in hosts: t = self._tqm._stats.summarize(h) self._display.display( "%s : %s %s %s %s" % (hostcolor(h, t), colorize('ok', t['ok'], 'green'), colorize('changed', t['changed'], 'yellow'), colorize('unreachable', t['unreachable'], 'red'), colorize('failed', t['failures'], 'red')), screen_only=True) self._display.display( "%s : %s %s %s %s" % (hostcolor(h, t, False), colorize('ok', t['ok'], None), colorize('changed', t['changed'], None), colorize('unreachable', t['unreachable'], None), colorize('failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True) # END STATS STUFF return result
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") self._write_log("PLAY RECAP") hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True ) self._write_log(u"%s -- %s : %s %s %s %s" % ( 'DONE', hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR))) self._display.display(u"%s : %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True ) self._display.display("", screen_only=True) # print custom stats if C.SHOW_CUSTOM_STATS and stats.custom: self._display.banner("CUSTOM STATS: ") # per host #TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display('\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace('\n',''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results(stats.custom['_run'], indent=1).replace('\n','')) self._display.display("", screen_only=True)
def run(self): ''' Run the given playbook, based on the settings in the play which may limit the runs to serialized groups, etc. ''' signal.signal(signal.SIGINT, self._cleanup) result = 0 entrylist = [] entry = {} try: for playbook_path in self._playbooks: pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader) if self._tqm is None: # we are doing a listing entry = {'playbook': playbook_path} entry['plays'] = [] i = 1 plays = pb.get_plays() self._display.vv('%d plays in %s' % (len(plays), playbook_path)) for play in plays: self._inventory.remove_restriction() # Create a temporary copy of the play here, so we can run post_validate # on it without the templating changes affecting the original object. all_vars = self._variable_manager.get_vars(loader=self._loader, play=play) templar = Templar(loader=self._loader, variables=all_vars) new_play = play.copy() new_play.post_validate(templar) if self._options.syntax: continue if self._tqm is None: # we are just doing a listing pname = new_play.get_name().strip() if pname == 'PLAY: <no name specified>': pname = 'PLAY: #%d' % i p = { 'name': pname } if self._options.listhosts: p['pattern']=play.hosts p['hosts']=set(self._inventory.get_hosts(new_play.hosts)) #TODO: play tasks are really blocks, need to figure out how to get task objects from them elif self._options.listtasks: p['tasks'] = [] for task in play.get_tasks(): p['tasks'].append(task) #p['tasks'].append({'name': task.get_name().strip(), 'tags': task.tags}) elif self._options.listtags: p['tags'] = set(new_play.tags) for task in play.get_tasks(): p['tags'].update(task) #p['tags'].update(task.tags) entry['plays'].append(p) else: # make sure the tqm has callbacks loaded self._tqm.load_callbacks() # we are actually running plays for batch in self._get_serialized_batches(new_play): if len(batch) == 0: self._tqm.send_callback('v2_playbook_on_play_start', new_play) self._tqm.send_callback('v2_playbook_on_no_hosts_matched') break # restrict the inventory to the hosts in the serialized batch self._inventory.restrict_to_hosts(batch) # and run it... result = self._tqm.run(play=play) # if the last result wasn't zero, break out of the serial batch loop if result != 0: break # if the last result wasn't zero, break out of the play loop if result != 0: break i = i + 1 # per play if entry: entrylist.append(entry) # per playbook # if the last result wasn't zero, break out of the playbook file name loop if result != 0: break if entrylist: return entrylist finally: if self._tqm is not None: self._cleanup() if self._options.syntax: self.display.display("No issues encountered") return result # FIXME: this stat summary stuff should be cleaned up and moved # to a new method, if it even belongs here... self._display.banner("PLAY RECAP") hosts = sorted(self._tqm._stats.processed.keys()) for h in hosts: t = self._tqm._stats.summarize(h) self._display.display("%s : %s %s %s %s" % ( hostcolor(h, t), colorize('ok', t['ok'], 'green'), colorize('changed', t['changed'], 'yellow'), colorize('unreachable', t['unreachable'], 'red'), colorize('failed', t['failures'], 'red')), screen_only=True ) self._display.display("%s : %s %s %s %s" % ( hostcolor(h, t, False), colorize('ok', t['ok'], None), colorize('changed', t['changed'], None), colorize('unreachable', t['unreachable'], None), colorize('failed', t['failures'], None)), log_only=True ) self._display.display("", screen_only=True) # END STATS STUFF return result
def v2_playbook_on_stats(self, stats): self._display.display("\n- Play recap -", screen_only=True) hosts = sorted(stats.processed.keys()) for h in hosts: # TODO how else can we display these? t = stats.summarize(h) self._display.display( u" %s : %s %s %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR), colorize(u'rescued', t['rescued'], C.COLOR_OK), colorize(u'ignored', t['ignored'], C.COLOR_WARN)), screen_only=True) self._display.display( u" %s : %s %s %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None), colorize(u'rescued', t['rescued'], None), colorize(u'ignored', t['ignored'], None)), log_only=True)
def v2_playbook_on_stats(self, stats): self._display.display("\n- Play recap -", screen_only=True) hosts = sorted(stats.processed.keys()) for h in hosts: # TODO how else can we display these? t = stats.summarize(h) self._display.display( u" %s : %s %s %s %s %s %s" % ( hostcolor(h, t), colorize(u"ok", t["ok"], C.COLOR_OK), colorize(u"changed", t["changed"], C.COLOR_CHANGED), colorize( u"unreachable", t["unreachable"], C.COLOR_UNREACHABLE ), colorize(u"failed", t["failures"], C.COLOR_ERROR), colorize(u"rescued", t["rescued"], C.COLOR_OK), colorize(u"ignored", t["ignored"], C.COLOR_WARN), ), screen_only=True, ) self._display.display( u" %s : %s %s %s %s %s %s" % ( hostcolor(h, t, False), colorize(u"ok", t["ok"], None), colorize(u"changed", t["changed"], None), colorize(u"unreachable", t["unreachable"], None), colorize(u"failed", t["failures"], None), colorize(u"rescued", t["rescued"], None), colorize(u"ignored", t["ignored"], None), ), log_only=True, ) if stats.custom and self.show_custom_stats: self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == "_run": continue self._display.display( "\t%s: %s" % ( k, self._dump_results(stats.custom[k], indent=1).replace( "\n", "" ), ) ) # print per run custom stats if "_run" in stats.custom: self._display.display("", screen_only=True) self._display.display( "\tRUN: %s" % self._dump_results( stats.custom["_run"], indent=1 ).replace("\n", "") ) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._display.display("\n- Play recap -", screen_only=True) hosts = sorted(stats.processed.keys()) for h in hosts: # TODO how else can we display these? t = stats.summarize(h) self._display.display( u" %s : %s %s %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR), colorize(u'rescued', t['rescued'], C.COLOR_OK), colorize(u'ignored', t['ignored'], C.COLOR_WARN)), screen_only=True) self._display.display( u" %s : %s %s %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None), colorize(u'rescued', t['rescued'], None), colorize(u'ignored', t['ignored'], None)), log_only=True) if stats.custom and self.show_custom_stats: self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display( '\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results( stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True)
def run(self): ''' Run the given playbook, based on the settings in the play which may limit the runs to serialized groups, etc. ''' signal.signal(signal.SIGINT, self._cleanup) result = 0 entrylist = [] entry = {} try: for playbook_path in self._playbooks: pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader) self._inventory.set_playbook_basedir( os.path.dirname(playbook_path)) if self._tqm is None: # we are doing a listing entry = {'playbook': playbook_path} entry['plays'] = [] i = 1 plays = pb.get_plays() self._display.vv('%d plays in %s' % (len(plays), playbook_path)) for play in plays: # clear any filters which may have been applied to the inventory self._inventory.remove_restriction() if play.vars_prompt: for var in play.vars_prompt: if 'name' not in var: raise AnsibleError( "'vars_prompt' item is missing 'name:'", obj=play._ds) vname = var['name'] prompt = var.get("prompt", vname) default = var.get("default", None) private = var.get("private", True) confirm = var.get("confirm", False) encrypt = var.get("encrypt", None) salt_size = var.get("salt_size", None) salt = var.get("salt", None) if vname not in play.vars: self._tqm.send_callback( 'v2_playbook_on_vars_prompt', vname, private, prompt, encrypt, confirm, salt_size, salt, default) play.vars[vname] = self._do_var_prompt( vname, private, prompt, encrypt, confirm, salt_size, salt, default) # Create a temporary copy of the play here, so we can run post_validate # on it without the templating changes affecting the original object. all_vars = self._variable_manager.get_vars( loader=self._loader, play=play) templar = Templar(loader=self._loader, variables=all_vars) new_play = play.copy() new_play.post_validate(templar) if self._options.syntax: continue if self._tqm is None: # we are just doing a listing entry['plays'].append(new_play) else: # make sure the tqm has callbacks loaded self._tqm.load_callbacks() # we are actually running plays for batch in self._get_serialized_batches(new_play): if len(batch) == 0: self._tqm.send_callback( 'v2_playbook_on_play_start', new_play) self._tqm.send_callback( 'v2_playbook_on_no_hosts_matched') break # restrict the inventory to the hosts in the serialized batch self._inventory.restrict_to_hosts(batch) # and run it... result = self._tqm.run(play=play) # if the last result wasn't zero, break out of the serial batch loop if result != 0: break # if the last result wasn't zero, break out of the play loop if result != 0: break i = i + 1 # per play if entry: entrylist.append(entry) # per playbook # if the last result wasn't zero, break out of the playbook file name loop if result != 0: break if entrylist: return entrylist finally: if self._tqm is not None: self._cleanup() if self._options.syntax: self.display.display("No issues encountered") return result # FIXME: this stat summary stuff should be cleaned up and moved # to a new method, if it even belongs here... self._display.banner("PLAY RECAP") hosts = sorted(self._tqm._stats.processed.keys()) for h in hosts: t = self._tqm._stats.summarize(h) self._display.display( "%s : %s %s %s %s" % (hostcolor(h, t), colorize('ok', t['ok'], 'green'), colorize('changed', t['changed'], 'yellow'), colorize('unreachable', t['unreachable'], 'red'), colorize('failed', t['failures'], 'red')), screen_only=True) self._display.display( "%s : %s %s %s %s" % (hostcolor(h, t, False), colorize('ok', t['ok'], None), colorize('changed', t['changed'], None), colorize('unreachable', t['unreachable'], None), colorize('failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True) # END STATS STUFF return result
def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") csvname = self.results['play']['name'] + 'scv' f = csv.writer(open(csvname, "wb+")) f.writerow( ["ip", "ok", "changed", "skipped", "unreachable", "failures"]) hosts = sorted(stats.processed.keys()) for h in hosts: t = stats.summarize(h) print("---", t, " ip:", h) print(type(t)) print(t['ok']) print([h, t['ok']]) f.writerow([ h, str(t['ok']), str(t['changed']), str(t['skipped']), str(t['unreachable']), str(t['failures']) ]) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t), colorize(u'ok', t['ok'], C.COLOR_OK), colorize(u'changed', t['changed'], C.COLOR_CHANGED), colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE), colorize(u'failed', t['failures'], C.COLOR_ERROR)), screen_only=True) self._display.display( u"%s : %s %s %s %s" % (hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None)), log_only=True) self._display.display("", screen_only=True) # print custom stats if C.SHOW_CUSTOM_STATS and stats.custom: self._display.banner("CUSTOM STATS: ") # per host #TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display( '\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace( '\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results( stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True)
def v2_playbook_on_stats(self, stats): self._display.banner('RECAP') def cell(v, style, align='right'): if v: return rich.align.Align(str(v), align=align, style=style) else: return rich.align.Align(str(v), align=align, style='dim') def stat_column(header, field, style): total = sum(field.values()) return rich.table.Column( header=rich.align.Align(header, align='center'), footer=cell(total, style=style) ) table = rich.table.Table( rich.table.Column(header='Host', footer='Total'), stat_column('OK', stats.ok, style='ok'), stat_column('Changed', stats.changed, style='changed'), stat_column('Unreachable', stats.dark, style='unreachable'), stat_column('Failed', stats.failures, style='failed'), stat_column('Skipped', stats.skipped, style='skipped'), stat_column('Rescued', stats.rescued, style='rescued'), stat_column('Ignored', stats.ignored, style='ignored'), rich.table.Column(header='Total'), box=SIMPLER, padding=(0, 0, 0, 0), # Top, Right, Bottom, Left pad_edge=False, show_edge=False, show_footer=True, ) overall_total = 0 for h in sorted(stats.processed.keys()): t = stats.summarize(h) host_total = sum(t.values()) overall_total += host_total table.add_row( h, cell(t['ok'], style='ok'), cell(t['changed'], style='changed'), cell(t['unreachable'], style='unreachable'), cell(t['failures'], style='failed'), cell(t['skipped'], style='skipped'), cell(t['rescued'], style='rescued'), cell(t['ignored'], style='ignored'), cell(host_total, style='default'), ) self._display.display( u"%s : %s %s %s %s %s %s %s" % ( hostcolor(h, t, False), colorize(u'ok', t['ok'], None), colorize(u'changed', t['changed'], None), colorize(u'unreachable', t['unreachable'], None), colorize(u'failed', t['failures'], None), colorize(u'skipped', t['skipped'], None), colorize(u'rescued', t['rescued'], None), colorize(u'ignored', t['ignored'], None), ), log_only=True ) table.columns[-1].footer = cell(overall_total, style='default') self._display.console.print(table) # print custom stats if required if stats.custom and self.show_custom_stats: self._display.banner("CUSTOM STATS: ") # per host # TODO: come up with 'pretty format' for k in sorted(stats.custom.keys()): if k == '_run': continue self._display.display('\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace('\n', ''))) # print per run custom stats if '_run' in stats.custom: self._display.display("", screen_only=True) self._display.display('\tRUN: %s' % self._dump_results(stats.custom['_run'], indent=1).replace('\n', '')) self._display.display("", screen_only=True) if context.CLIARGS['check'] and self.check_mode_markers: self._display.banner("DRY RUN")