diff --git a/lib/ansible/module_utils/network/nxos/nxos.py b/lib/ansible/module_utils/network/nxos/nxos.py index 52718283a3..cebde4853a 100644 --- a/lib/ansible/module_utils/network/nxos/nxos.py +++ b/lib/ansible/module_utils/network/nxos/nxos.py @@ -164,8 +164,7 @@ class Cli: msgs = [] try: responses = connection.edit_config(config) - out = json.loads(responses)[1:-1] - msg = out + msg = json.loads(responses) except ConnectionError as e: code = getattr(e, 'code', 1) message = getattr(e, 'err', e) diff --git a/lib/ansible/plugins/cliconf/nxos.py b/lib/ansible/plugins/cliconf/nxos.py index 5172ac751c..6c3a756555 100644 --- a/lib/ansible/plugins/cliconf/nxos.py +++ b/lib/ansible/plugins/cliconf/nxos.py @@ -25,6 +25,7 @@ from itertools import chain from ansible.errors import AnsibleConnectionFailure 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 @@ -86,8 +87,8 @@ class Cliconf(CliconfBase): responses = [] for cmd in chain(['configure'], to_list(command), ['end']): responses.append(self.send_command(cmd)) - - return json.dumps(responses) + resp = responses[1:-1] + return json.dumps(resp) def get(self, command, prompt=None, answer=None, sendonly=False): return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly) diff --git a/lib/ansible/plugins/httpapi/nxos.py b/lib/ansible/plugins/httpapi/nxos.py index 13385da58f..2aee30ccfb 100644 --- a/lib/ansible/plugins/httpapi/nxos.py +++ b/lib/ansible/plugins/httpapi/nxos.py @@ -80,8 +80,15 @@ class HttpApi: # Migrated from module_utils def edit_config(self, command): + resp = list() responses = self.send_request(command, output='config') - return json.dumps(responses) + for response in to_list(responses): + if response != '{}': + resp.append(response) + if not resp: + resp = [''] + + return json.dumps(resp) def run_commands(self, commands, check_rc=True): """Runs list of commands on remote device and returns results