diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index 1ab35482df..12568a986d 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -165,16 +165,21 @@ class Cli: def load_config(self, config): """Sends configuration commands to the remote device """ + rc, out, err = self.exec_command('configure') if rc != 0: self._module.fail_json(msg='unable to enter configuration mode', output=to_text(err, errors='surrogate_then_replace')) + msgs = [] for cmd in config: rc, out, err = self.exec_command(cmd) if rc != 0: self._module.fail_json(msg=to_text(err, errors='surrogate_then_replace')) + elif out: + msgs.append(out) self.exec_command('end') + return msgs class Nxapi: @@ -343,6 +348,7 @@ class Nxapi: """ commands = to_list(commands) self.send_request(commands, output='config') + return [] def is_json(cmd): diff --git a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py index 3241003619..a4f3747e4b 100644 --- a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py +++ b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py @@ -748,7 +748,7 @@ def main(): if candidate: candidate = candidate.items_text() - load_config(module, candidate) + warnings.extend(load_config(module, candidate)) result['changed'] = True result['commands'] = candidate else: diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index 0945a31e91..bec126210b 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -204,7 +204,7 @@ class Connection(Rpc, _Connection): """Removes elements from the response before returning to the caller""" cleaned = [] for line in resp.splitlines(): - if (command and line.startswith(command.strip())) or self._matched_prompt.strip() in line: + if (command and line.strip() == command.strip()) or self._matched_prompt.strip() in line: continue cleaned.append(line) return b'\n'.join(cleaned).strip() diff --git a/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py b/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py index ded3319be5..c00bcb3b66 100644 --- a/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py +++ b/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py @@ -43,7 +43,7 @@ class TestNxosBgpNeighborAfModule(TestNxosModule): def load_fixtures(self, commands=None, device=''): self.get_config.return_value = load_fixture('', 'nxos_bgp_config.cfg') - self.load_config.return_value = None + self.load_config.return_value = [] def test_nxos_bgp_neighbor_af(self): set_module_args(dict(asn=65535, neighbor='3.3.3.3', afi='ipv4',