Exemplo n.º 1
0
    def v2_runner_on_skipped(self, result):
        # stat_logger.info(f'>>>>>>>>>in runner on skipped: {json.dumps(result._result, indent=4)}')
        schedule_logger(self._job_id).info(
            f"<TASK SKIPPED> Host {result._host} executes task {result._task._uuid} {result._task._attributes.get('name')} skipped. Details: {json.dumps(result._result, indent=4)}"
        )
        update_info = {
            'job_id': self._job_id,
            'play_id': self._play_id,
            'task_id': result._task._uuid,
            'status': TaskStatus.SKIPPED,
            'end_time': current_timestamp(),
            'host': result._host
        }
        JobSaver.update_task(update_info)
        JobSaver.update_task_status(update_info)
        # schedule_logger(self._job_id).info(f'>>>>>>>>>in runner on skipped: {json.dumps(result._result, indent=4)}')

        if self.display_skipped_hosts:
            self._clean_results(result._result, result._task.action)

            if self._last_task_banner != result._task._uuid:
                self._print_task_banner(result._task)

            if result._task.loop and 'results' in result._result:
                self._process_items(result)
            else:
                msg = "skipping: [%s]" % result._host.get_name()
                if self._run_is_verbose(result):
                    msg += " => %s" % self._dump_results(result._result)
                self._display.display(msg, color=C.COLOR_SKIP)
Exemplo n.º 2
0
    def v2_runner_on_failed(self, result, ignore_errors=False):
        # schedule_logger(self._job_id).error(f"Run on failed, result: {result._task._uuid}")
        # schedule_logger(self._job_id).error(f"Run on failed, details: {result.__dict__}")
        # stat_logger.info(f'>>>>>>>>>run on ok failed: {json.dumps(result._result, indent=4)}')
        schedule_logger(self._job_id).error(
            f"<TASK FAILED> Host {result._host} executes task {result._task._uuid} {result._task._attributes.get('name')} failed. Details: {json.dumps(result._result, indent=4)}"
        )
        update_info = {
            'job_id': self._job_id,
            'play_id': self._play_id,
            'task_id': result._task._uuid,
            'end_time': current_timestamp(),
            'status': TaskStatus.FAILED,
        }
        JobSaver.update_task(update_info)
        JobSaver.update_task_status(update_info)
        JobSaver.update_play(update_info)
        JobSaver.update_play_status(update_info)
        JobSaver.update_job(update_info)
        JobSaver.update_job_status(update_info)

        delegated_vars = result._result.get('_ansible_delegated_vars', None)
        self._clean_results(result._result, result._task.action)

        if self._last_task_banner != result._task._uuid:
            self._print_task_banner(result._task)

        self._handle_exception(result._result,
                               use_stderr=self.display_failed_stderr)
        self._handle_warnings(result._result)

        if result._task.loop and 'results' in result._result:
            self._process_items(result)

        else:
            if delegated_vars:
                self._display.display(
                    "fatal: [%s -> %s]: FAILED! => %s" %
                    (result._host.get_name(), delegated_vars['ansible_host'],
                     self._dump_results(result._result)),
                    color=C.COLOR_ERROR,
                    stderr=self.display_failed_stderr)
            else:
                self._display.display("fatal: [%s]: FAILED! => %s" %
                                      (result._host.get_name(),
                                       self._dump_results(result._result)),
                                      color=C.COLOR_ERROR,
                                      stderr=self.display_failed_stderr)

        if ignore_errors:
            self._display.display("...ignoring", color=C.COLOR_SKIP)
Exemplo n.º 3
0
    def v2_runner_on_unreachable(self, result):
        try:
            schedule_logger(self._job_id).error(
                f"<HOST UNREACHABLE> Host {result._host} executes task {result._task._uuid} {result._task._attributes.get('name')} unreachable. \nDetails: {json.dumps(result._result, indent=4)}"
            )
            # schedule_logger(self._job_id).info(f'>>>>>>>>>in runner on unreachable: {json.dumps(result._result, indent=4)}')
            # stat_logger.info(f'>>>>>>>>>in runner on unreachable: {json.dumps(result._result, indent=4)}')

            update_info = {
                'job_id': self._job_id,
                'play_id': self._play_id,
                'task_id': result._task._uuid,
                'end_time': current_timestamp(),
                'status': TaskStatus.FAILED,
            }
            JobSaver.update_task(update_info)
            JobSaver.update_task_status(update_info)
            JobSaver.update_play(update_info)
            JobSaver.update_play_status(update_info)
        except Exception:
            schedule_logger(self._job_id).warning(
                f"In v2_runner_on_unreachable, details: {traceback.format_exc()}"
            )

        if self._last_task_banner != result._task._uuid:
            self._print_task_banner(result._task)

        delegated_vars = result._result.get('_ansible_delegated_vars', None)
        if delegated_vars:
            msg = "fatal: [%s -> %s]: UNREACHABLE! => %s" % (
                result._host.get_name(), delegated_vars['ansible_host'],
                self._dump_results(result._result))
        else:
            msg = "fatal: [%s]: UNREACHABLE! => %s" % (
                result._host.get_name(), self._dump_results(result._result))
        self._display.display(msg,
                              color=C.COLOR_UNREACHABLE,
                              stderr=self.display_failed_stderr)
Exemplo n.º 4
0
 def v2_runner_on_start(self, host, task):
     # schedule_logger(self._job_id).info(f"in v2 runner on start, host: {host}, task: {task}, task id: {task._uuid}")
     schedule_logger(self._job_id).info(
         f"<START TASK> Starting task. Host: {host}. task id: {task._uuid}, task name: {task._attributes.get('name')}"
     )
     update_info = {
         'job_id': self._job_id,
         'play_id': self._play_id,
         'task_id': task._uuid,
         'task_name': task._attributes.get('name'),
         'status': TaskStatus.RUNNING,
         'start_time': current_timestamp(),
         'role': task._role,
         'host': host
     }
     JobSaver.update_task(update_info)
     JobSaver.update_task_status(update_info)
     #
     # schedule_logger(self._job_id).info(f"<TASK ON START> host: {host}, task id: {task._uuid}, task name: {task._attribute.get('name')}")
     # schedule_logger(self._job_id).info(f"<TASK ON START> host: {host}, task id: {task._uuid}, task name: {task._attribute.get('name')}")
     if self.get_option('show_per_host_start'):
         self._display.display(" [started %s on %s]" % (task, host),
                               color=C.COLOR_OK)
Exemplo n.º 5
0
    def v2_runner_on_ok(self, result):
        try:
            schedule_logger(self._job_id).info(
                f"<TASK SUCCESS> Host {result._host}, type of host: {type(result._host)} "
            )

            host_logger(self._job_id, result._host).info(
                f"<TASK SUCCESS> Task id: {result._task._uuid}, name: {result._task._attributes.get('name')} executed successfully on host {result._host}"
            )
            schedule_logger(self._job_id).info(
                f"<TASK SUCCESS> Host {result._host} executes task {result._task._uuid} {result._task._attributes.get('name')} successfully. Details: {json.dumps(result._result, indent=4)}"
            )
            # schedule_logger(self._job_id).info(f"Run on ok, details: {json.dumps(result._result, indent=4)}")
            schedule_logger(
                self._job_id).info(f"<RESULT INFO> f{result.__dict__}")
            update_info = {
                'job_id': self._job_id,
                'play_id': self._play_id,
                'task_id': result._task._uuid,
                'task_name': result._task._attributes.get('name'),
                'status': TaskStatus.SUCCESS,
                'end_time': current_timestamp(),
                'role': result._task._role
            }
            JobSaver.update_task(update_info)
            JobSaver.update_task_status(update_info)

        except Exception:
            schedule_logger(self._job_id).warning(
                f"In v2_runner_on_ok: details: {traceback.format_exc()}")

        delegated_vars = result._result.get('_ansible_delegated_vars', None)

        if isinstance(result._task, TaskInclude):
            return
        elif result._result.get('changed', False):
            if self._last_task_banner != result._task._uuid:
                self._print_task_banner(result._task)

            if delegated_vars:
                msg = "changed: [%s -> %s]" % (result._host.get_name(),
                                               delegated_vars['ansible_host'])
            else:
                msg = "changed: [%s]" % result._host.get_name()
            color = C.COLOR_CHANGED
        else:
            if not self.display_ok_hosts:
                return

            if self._last_task_banner != result._task._uuid:
                self._print_task_banner(result._task)

            if delegated_vars:
                msg = "ok: [%s -> %s]" % (result._host.get_name(),
                                          delegated_vars['ansible_host'])
            else:
                msg = "ok: [%s]" % result._host.get_name()
            color = C.COLOR_OK

        self._handle_warnings(result._result)

        if result._task.loop and 'results' in result._result:
            self._process_items(result)
        else:
            self._clean_results(result._result, result._task.action)

            if self._run_is_verbose(result):
                msg += " => %s" % (self._dump_results(result._result), )
            self._display.display(msg, color=color)