diff --git a/lib/ansible/module_utils/network/ios/ios.py b/lib/ansible/module_utils/network/ios/ios.py index fc690c98fd4..1cbac6bcecc 100644 --- a/lib/ansible/module_utils/network/ios/ios.py +++ b/lib/ansible/module_utils/network/ios/ios.py @@ -165,4 +165,4 @@ def run_commands(module, commands, check_rc=True): def load_config(module, commands): connection = get_connection(module) - out = connection.edit_config(commands) + return connection.edit_config(commands) diff --git a/lib/ansible/modules/network/ios/ios_l3_interface.py b/lib/ansible/modules/network/ios/ios_l3_interface.py index 59c1e7eaa82..1547667b31f 100644 --- a/lib/ansible/modules/network/ios/ios_l3_interface.py +++ b/lib/ansible/modules/network/ios/ios_l3_interface.py @@ -296,9 +296,6 @@ def main(): result = {'changed': False} - if warnings: - result['warnings'] = warnings - want = map_params_to_obj(module) have = map_config_to_obj(module) @@ -307,10 +304,14 @@ def main(): if commands: if not module.check_mode: - load_config(module, commands) + resp = load_config(module, commands) + warnings.extend((out for out in resp if out)) result['changed'] = True + if warnings: + result['warnings'] = warnings + module.exit_json(**result) diff --git a/lib/ansible/plugins/cliconf/__init__.py b/lib/ansible/plugins/cliconf/__init__.py index e613cf39ebf..2ca50b60a05 100644 --- a/lib/ansible/plugins/cliconf/__init__.py +++ b/lib/ansible/plugins/cliconf/__init__.py @@ -183,7 +183,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)): ssh = self._connection.paramiko_conn._connect_uncached() if proto == 'scp': if not HAS_SCP: - self._connection.internal_error("Required library scp is not installed. Please install it using `pip install scp`") + raise AnsibleError("Required library scp is not installed. Please install it using `pip install scp`") with SCPClient(ssh.get_transport(), socket_timeout=timeout) as scp: out = scp.put(source, destination) elif proto == 'sftp': @@ -195,7 +195,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)): ssh = self._connection.paramiko_conn._connect_uncached() if proto == 'scp': if not HAS_SCP: - self._connection.internal_error("Required library scp is not installed. Please install it using `pip install scp`") + raise AnsibleError("Required library scp is not installed. Please install it using `pip install scp`") with SCPClient(ssh.get_transport(), socket_timeout=timeout) as scp: scp.get(source, destination) elif proto == 'sftp': diff --git a/lib/ansible/plugins/cliconf/ios.py b/lib/ansible/plugins/cliconf/ios.py index ff2a6b048a0..28839072471 100644 --- a/lib/ansible/plugins/cliconf/ios.py +++ b/lib/ansible/plugins/cliconf/ios.py @@ -72,6 +72,7 @@ class Cliconf(CliconfBase): @enable_mode def edit_config(self, command): + results = [] for cmd in chain(['configure terminal'], to_list(command), ['end']): if isinstance(cmd, dict): command = cmd['command'] @@ -84,7 +85,8 @@ class Cliconf(CliconfBase): answer = None newline = True - self.send_command(command, prompt, answer, False, newline) + results.append(self.send_command(command, prompt, answer, False, newline)) + return results[1:-1] def get(self, command, prompt=None, answer=None, sendonly=False): return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly) diff --git a/test/integration/targets/ios_l3_interface/tests/cli/basic.yaml b/test/integration/targets/ios_l3_interface/tests/cli/basic.yaml index 58c0fd85de2..c943b6f00cc 100644 --- a/test/integration/targets/ios_l3_interface/tests/cli/basic.yaml +++ b/test/integration/targets/ios_l3_interface/tests/cli/basic.yaml @@ -22,7 +22,7 @@ - name: Configure interface ipv4 address ios_l3_interface: name: "{{ test_interface }}" - ipv4: 192.168.0.1/24 + ipv4: 192.168.20.1/24 state: present provider: "{{ cli }}" register: result @@ -31,12 +31,12 @@ that: - 'result.changed == true' - '"interface {{ test_interface }}" in result.commands' - - '"ip address 192.168.0.1 255.255.255.0" in result.commands' + - '"ip address 192.168.20.1 255.255.255.0" in result.commands' - name: Configure interface ipv4 address (idempotent) ios_l3_interface: name: "{{ test_interface }}" - ipv4: 192.168.0.1/24 + ipv4: 192.168.20.1/24 state: present provider: "{{ cli }}" register: result @@ -48,7 +48,7 @@ - name: Assign same ipv4 address to other interface (fail) ios_l3_interface: name: "{{ test_interface2 }}" - ipv4: 192.168.0.1/24 + ipv4: 192.168.20.1/24 state: present provider: "{{ cli }}" ignore_errors: yes