def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=False): if result.get('_ansible_no_log', False): return json.dumps( dict( censored= "The output has been hidden due to the fact that 'no_log: true' was specified for this result" )) # All result keys stating with _ansible_ are internal, so remove them from the result before we output anything. abridged_result = strip_internal_keys(module_response_deepcopy(result)) # remove invocation unless specifically wanting it if not keep_invocation and self._display.verbosity < 3 and 'invocation' in result: del abridged_result['invocation'] # remove diff information from screen output if self._display.verbosity < 3 and 'diff' in result: del abridged_result['diff'] # remove exception from screen output if 'exception' in abridged_result: del abridged_result['exception'] dumped = '' # put changed and skipped into a header line if 'changed' in abridged_result: dumped += 'changed=' + str( abridged_result['changed']).lower() + ' ' del abridged_result['changed'] if 'skipped' in abridged_result: dumped += 'skipped=' + str( abridged_result['skipped']).lower() + ' ' del abridged_result['skipped'] # if we already have stdout, we don't need stdout_lines if 'stdout' in abridged_result and 'stdout_lines' in abridged_result: abridged_result['stdout_lines'] = '<omitted>' # if we already have stderr, we don't need stderr_lines if 'stderr' in abridged_result and 'stderr_lines' in abridged_result: abridged_result['stderr_lines'] = '<omitted>' if abridged_result: dumped += '\n' dumped += to_text( yaml.dump(abridged_result, allow_unicode=True, width=1000, Dumper=AnsibleDumper, default_flow_style=False)) # indent by a couple of spaces dumped = '\n '.join(dumped.split('\n')).rstrip() return dumped
def v2_runner_on_ok(self, result): self._clean_results(result._result, result._task.action) if 'ansible_facts' in result._result: return elif 'hostvars[inventory_hostname]' in result._result: facts = result._result['hostvars[inventory_hostname]'] facter_keys = [k for k in facts.keys() if k.startswith('facter_')] for key in facter_keys: del facts[key] result._result['ansible_facts'] = facts self._display.display( "%s | %s | Gathered facts:\n%s" % ( _get_timestamp(), result._host.get_name(), yaml.safe_dump(facts, default_flow_style=False))) return if result._task.action in C.MODULE_NO_JSON: self._display.display( self._command_generic_msg( result._host.get_name(), result._result, result._task, "SUCCESS")) else: if 'changed' in result._result and result._result['changed']: self._display.display( "%s | %s | SUCCESS => %s" % ( _get_timestamp(), result._host.get_name(), self._dump_results( result._result, indent=4))) else: abriged_result = strip_internal_keys(result._result) if 'msg' in abriged_result and len(abriged_result.keys()) == 1: result_text = result._result['msg'] else: result_text = self._dump_results(result._result, indent=4) self._display.display( "%s | %s | %s | %s" % ( _get_timestamp(), result._host.get_name(), result._task.get_name().strip(), result_text)) self._handle_warnings(result._result)
def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=False): if result.get('_ansible_no_log', False): return json.dumps(dict(censored="the output has been hidden due to the fact that 'no_log: true' was specified for this result")) # All result keys stating with _ansible_ are internal, so remove them from the result before we output anything. abridged_result = strip_internal_keys(result) # remove invocation unless specifically wanting it if not keep_invocation and self._display.verbosity < 3 and 'invocation' in result: del abridged_result['invocation'] # remove diff information from screen output if self._display.verbosity < 3 and 'diff' in result: del abridged_result['diff'] # remove exception from screen output if 'exception' in abridged_result: del abridged_result['exception'] dumped = '' # put changed and skipped into a header line if 'changed' in abridged_result: dumped += 'changed=' + str(abridged_result['changed']).lower() + ' ' del abridged_result['changed'] if 'skipped' in abridged_result: dumped += 'skipped=' + str(abridged_result['skipped']).lower() + ' ' del abridged_result['skipped'] # if we already have stdout, we don't need stdout_lines if 'stdout' in abridged_result and 'stdout_lines' in abridged_result: abridged_result['stdout_lines'] = '<omitted>' if abridged_result: dumped += '\n' dumped += yaml.dump(abridged_result, width=1000, Dumper=AnsibleDumper, default_flow_style=False) # indent by a couple of spaces dumped = '\n '.join(dumped.split('\n')).rstrip() return dumped
def _format_results(self, result, indent=None, sort_keys=True, keep_invocation=False): # All result keys stating with _ansible_ are internal, so remove them from the result before we output anything. abridged_result = strip_internal_keys(result._result) # remove invocation unless specifically wanting it if not keep_invocation and self._display.verbosity < 3 and 'invocation' in abridged_result: del abridged_result['invocation'] # remove diff information from screen output if self._display.verbosity < 3 and 'diff' in abridged_result: del abridged_result['diff'] if 'access_control_allow_headers' in abridged_result: del abridged_result['access_control_allow_headers'] if 'access_control_allow_methods' in abridged_result: del abridged_result['access_control_allow_methods'] if 'access_control_allow_origin' in abridged_result: del abridged_result['access_control_allow_origin'] if 'x_content_type_options' in abridged_result: del abridged_result['x_content_type_options'] # remove exception from screen output if 'exception' in abridged_result: del abridged_result['exception'] dumped = '' dumpd_tile = '[' + str( result._host.name) + ']: Ansible Failed! ==>\n ' # put changed and skipped into a header line if 'changed' in abridged_result: dumped += 'changed=' + str( abridged_result['changed']).lower() + ' ' del abridged_result['changed'] if 'skipped' in abridged_result: dumped += 'skipped=' + str( abridged_result['skipped']).lower() + ' ' del abridged_result['skipped'] # if we already have stdout, we don't need stdout_lines if 'stdout' in abridged_result and 'stdout_lines' in abridged_result: abridged_result['stdout_lines'] = '<omitted>' if abridged_result: dumped += '\n' dumped += yaml.dump(abridged_result, width=1000, Dumper=AnsibleDumper, default_flow_style=False) # indent by a couple of spaces dumped = '\n '.join(dumped.split('\n')).rstrip() return dumpd_tile + dumped + '\n'