Ejemplo n.º 1
0
    def _dump_results(self,
                      result,
                      indent=None,
                      sort_keys=True,
                      keep_invocation=False):
        '''Properly format JSON output.'''
        save = {}
        for key in [
                'stdout', 'stdout_lines', 'stderr', 'stderr_lines', 'msg',
                'module_stdout', 'module_stderr'
        ]:
            if key in result:
                save[key] = result.pop(key)

        output = CallbackModule_default._dump_results(self, result)

        for key in [
                'stdout', 'stderr', 'msg', 'module_stdout', 'module_stderr'
        ]:
            if key in save and save[key]:
                output += '\n\n%s:\n\n%s\n' % (key.upper(), save[key])

        for key, value in save.items():
            result[key] = value

        return output
Ejemplo n.º 2
0
    def _dump_results(self, result):
        '''Return the text to output for a result.'''

        # Enable JSON identation
        result['_ansible_verbose_always'] = True

        save = {}
        for key in [
                'stdout', 'stdout_lines', 'stderr', 'stderr_lines', 'msg',
                'module_stdout', 'module_stderr'
        ]:
            if key in result:
                save[key] = result.pop(key)

        output = CallbackModule_default._dump_results(self, result)

        for key in [
                'stdout', 'stderr', 'msg', 'module_stdout', 'module_stderr'
        ]:
            if key in save and save[key]:
                output += '\n\n%s:\n\n%s\n' % (key.upper(), save[key])

        for key, value in save.items():
            result[key] = value

        return output
Ejemplo n.º 3
0
    def _dump_results(self, result):
        # Enable JSON identation
        result['_ansible_verbose_always'] = True

        save = {}
        # Reference for common return values:
        # https://docs.ansible.com/ansible/2.7/reference_appendices/common_return_values.html
        for key in [
                'stdout', 'stdout_lines', 'stderr', 'stderr_lines', 'msg',
                'invocation'
        ]:
            if key in result:
                save[key] = result.pop(key)

        output = CallbackModule_default._dump_results(self, result)

        # Exclude stdout_lines, stderr_lines in output.
        for key in ['stdout', 'stderr', 'msg']:
            if key in save and save[key]:
                output += '\n\n%s:\n\n%s\n' % (key.upper(), save[key])

        # Deal with 'invocation'.
        if 'invocation' in save and save['invocation']:
            invocation = json.dumps(save['invocation'],
                                    indent=4)  # Pretty printed json.
            output += '\n\n%s:\n\n%s\n' % ('INVOCATION', invocation)

        for key, value in save.items():
            result[key] = value

        return output
Ejemplo n.º 4
0
 def _dump_results(self,
                   result,
                   indent=None,
                   sort_keys=True,
                   keep_invocation=False):
     return CallbackModule_default._dump_results(self,
                                                 result,
                                                 indent=4,
                                                 sort_keys=True,
                                                 keep_invocation=False)
Ejemplo n.º 5
0
    def _dump_results(self, result):
        '''Return the text to output for a result.'''

        result['_ansible_verbose_always'] = True

        save = {}
        for key in ['stdout', 'stdout_lines', 'stderr', 'stderr_lines', 'msg', 'module_stdout', 'module_stderr']:
            if key in result:
                save[key] = result.pop(key)

        output = CallbackModule_default._dump_results(self, result)

        for key in ['stdout', 'stderr', 'msg', 'module_stdout', 'module_stderr']:
            if key in save and save[key]:
                output += '\n\n%s:\n\n%s\n' % (key.upper(), save[key])

        for key, value in save.items():
            result[key] = value

        return output
Ejemplo n.º 6
0
    def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=False):
        '''Return the text to output for a result.'''

        # Enable JSON identation
        result['_ansible_verbose_always'] = True

        save = {}
        for key in ['stdout', 'stdout_lines', 'stderr', 'stderr_lines', 'msg', 'module_stdout', 'module_stderr']:
            if key in result:
                save[key] = result.pop(key)

        output = CallbackModule_default._dump_results(self, result)

        for key in ['stdout', 'stderr', 'msg', 'module_stdout', 'module_stderr']:
            if key in save and save[key]:
                output += '\n\n%s:\n\n%s\n' % (key.upper(), save[key])

        for key, value in save.items():
            result[key] = value

        return output
Ejemplo n.º 7
0
    def _dump_results(self,
                      result,
                      indent=None,
                      sort_keys=True,
                      keep_invocation=False):
        '''Return the text to output for a result.'''

        # Enable JSON identation
        result['_ansible_verbose_always'] = True

        save = {}
        for key in [
                'stdout', 'stdout_lines', 'stderr', 'stderr_lines', 'msg',
                'log', 'module_stdout', 'module_stderr'
        ]:
            if key in result:
                save[key] = result.pop(key)

        output = CallbackModule_default._dump_results(self, result)

        print("\e[31m Hello world \e[0m")

        CRED = '\033[91m'
        CEND = '\033[0m'
        content = ''

        for key in [
                'stdout', 'stderr', 'msg', 'log', 'module_stdout',
                'module_stderr'
        ]:
            if key in save and save[key]:
                if key == 'log':
                    # print("this key is log")
                    # print(save[key])
                    lines = save[key].split('\n')
                    for line in lines:

                        if operator.contains(line.lower(), "text"):
                            data = line.lower().split(" text: ")
                            content += '\n' + data[0]

                            json_object = json.loads(data[1])
                            # json_formatted_str = json.dumps(json_object, indent=2)
                            formatted_json = json.dumps(json_object,
                                                        sort_keys=True,
                                                        indent=4)
                            colorful_json = highlight(
                                formatted_json, lexers.JsonLexer(),
                                formatters.TerminalFormatter())
                            content += '\n' + CRED + "Text:" + CEND
                            content += '\n' + CRED + colorful_json + CEND + '\n'

                        elif operator.contains(line.lower(), "headers are:"):
                            data = line.lower().split(" headers are: ")
                            content += '\n' + data[0]
                            content += '\n' + CRED + "Headers are:" + CEND
                            content += '\n' + CRED + data[1] + CEND + '\n'

                        elif operator.contains(line.lower(), "input data:"):
                            data = line.lower().split(" input data: ")
                            content += '\n' + data[0]
                            content += '\n' + CRED + "Input Data:" + CEND
                            content += '\n' + CRED + data[1] + CEND + '\n'

                        else:
                            content += '\n' + line

                    # add content to output:
                    output += '\n\n%s:\n\n%s\n' % (key.upper(), content)
                else:
                    # print("this key issnt log")
                    output += '\n\n%s:\n\n%s\n' % (key.upper(), save[key])

            # logging.warning(output)

        for key, value in save.items():
            result[key] = value

        return output