Esempio n. 1
0
    def handle_result(self, result):
        """Handle an incoming result object."""
        scan_data_log.safe_log_ansible_result(result, self.scan_task)
        # pylint: disable=protected-access
        result_obj = _construct_result(result)
        self.results.append(result_obj)
        logger.debug('%s', result_obj)

        # 'timeout' returns 124 on timeouts
        if result_obj[RESULT].get(FAILED) and \
           result_obj[RESULT].get(RC) == TIMEOUT_RC:
            logger.warning('Task %s timed out', result_obj[KEY])

        host = result_obj[HOST]
        results_to_store = normalize_result(result)
        host_facts = {}
        if result._task_fields.get('action') == 'set_fact' and \
                result.task_name == 'internal_host_started_processing_role':
            role_name = result._result.get(
                ANSIBLE_FACTS).get(STARTED_PROCESSING_ROLE)
            log_message = 'PROCESSING %s - ANSIBLE ROLE %s' % (host, role_name)
            self.scan_task.log_message(log_message)
        for key, value in results_to_store:
            if key == HOST_DONE:
                self._finalize_host(host, SystemInspectionResult.SUCCESS)
            else:
                processed_value = process.process(
                    self.scan_task, host_facts, key, value, host)
                host_facts[key] = processed_value

        if bool(host_facts):
            if host in self._ansible_facts:
                self._ansible_facts[host].update(host_facts)
            else:
                self._ansible_facts[host] = host_facts
Esempio n. 2
0
    def v2_runner_on_unreachable(self, result):
        """Print a json representation of the result."""
        try:
            scan_data_log.safe_log_ansible_result(result, self.scan_task)
            result_obj = _construct_result(result)
            self.results.append(result_obj)
            logger.warning('%s', result_obj)

            # pylint: disable=protected-access
            unreachable_host = result._host.name
            result_message = result._result.get(
                'msg', 'No information given on unreachable warning.  '
                'Missing msg attribute.')
            message = 'UNREACHABLE %s. %s' % (unreachable_host, result_message)
            self.scan_task.log_message(message, log_level=logging.ERROR)

            self._finalize_host(unreachable_host,
                                SystemInspectionResult.UNREACHABLE)
        except Exception as error:
            self.scan_task.log_message(
                'UNEXPECTED FAILURE in v2_runner_on_unreachable.'
                '  Error: %s\nAnsible result: %s' % (error, result._result),
                log_level=logging.ERROR)
            traceback.print_exc()
            raise error
Esempio n. 3
0
    def v2_runner_on_unreachable(self, result):
        """Print a json representation of the result."""
        scan_data_log.safe_log_ansible_result(result, self.scan_task)
        result_obj = _construct_result(result)
        self.results.append(result_obj)
        logger.warning('%s', result_obj)

        # pylint: disable=protected-access
        unreachable_host = result._host.name
        result_message = result._result.get(
            'msg', 'No information given on unreachable warning.  '
            'Missing msg attribute.')
        message = 'UNREACHABLE %s. %s' % (unreachable_host, result_message)
        self.scan_task.log_message(message, log_level=logging.ERROR)

        self._finalize_host(unreachable_host,
                            SystemInspectionResult.UNREACHABLE)