From d028a0257a32294a377f8cec70e02c8b03ea7814 Mon Sep 17 00:00:00 2001 From: Nathaniel Case <this.is@nathanielca.se> Date: Wed, 23 May 2018 10:09:50 -0400 Subject: [PATCH] Change default output of NXAPI to text to match CLI (#40607) * Default output format for nxapi now 'text' * Apply json output to both types of input * Add missing ConnectionError import to cliconf plugins --- lib/ansible/plugins/cliconf/eos.py | 1 + lib/ansible/plugins/cliconf/nxos.py | 1 + lib/ansible/plugins/httpapi/nxos.py | 14 ++++++++------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ansible/plugins/cliconf/eos.py b/lib/ansible/plugins/cliconf/eos.py index d884f43af7..d6a1efd1d6 100644 --- a/lib/ansible/plugins/cliconf/eos.py +++ b/lib/ansible/plugins/cliconf/eos.py @@ -25,6 +25,7 @@ import time from itertools import chain from ansible.module_utils._text import to_bytes +from ansible.module_utils.connection import ConnectionError from ansible.module_utils.network.common.utils import to_list from ansible.plugins.cliconf import CliconfBase, enable_mode from ansible.plugins.connection.network_cli import Connection as NetworkCli diff --git a/lib/ansible/plugins/cliconf/nxos.py b/lib/ansible/plugins/cliconf/nxos.py index afd43ff689..6fd75a706c 100644 --- a/lib/ansible/plugins/cliconf/nxos.py +++ b/lib/ansible/plugins/cliconf/nxos.py @@ -24,6 +24,7 @@ import json from itertools import chain from ansible.module_utils._text import to_bytes, to_text +from ansible.module_utils.connection import ConnectionError from ansible.module_utils.network.common.utils import to_list from ansible.plugins.cliconf import CliconfBase from ansible.plugins.connection.network_cli import Connection as NetworkCli diff --git a/lib/ansible/plugins/httpapi/nxos.py b/lib/ansible/plugins/httpapi/nxos.py index d6c2210b99..a9b37d729e 100644 --- a/lib/ansible/plugins/httpapi/nxos.py +++ b/lib/ansible/plugins/httpapi/nxos.py @@ -35,22 +35,24 @@ class HttpApi: responses = list() for item in to_list(data): - cmd_output = message_kwargs.get('output', 'json') + cmd_output = message_kwargs.get('output', 'text') if isinstance(item, dict): command = item['command'] - if command.endswith('| json'): - command = command.rsplit('|', 1)[0] - cmd_output = 'json' - elif 'output' in item: + if 'output' in item: cmd_output = item['output'] else: command = item + # Emulate '| json' from CLI + if command.endswith('| json'): + command = command.rsplit('|', 1)[0] + cmd_output = 'json' + if output and output != cmd_output: responses.extend(self._run_queue(queue, output)) queue = list() - output = cmd_output or 'json' + output = cmd_output queue.append(command) if queue: