diff --git a/lib/ansible/modules/network/ios/ios_command.py b/lib/ansible/modules/network/ios/ios_command.py index a5c79d2194..0729a761f6 100644 --- a/lib/ansible/modules/network/ios/ios_command.py +++ b/lib/ansible/modules/network/ios/ios_command.py @@ -131,6 +131,7 @@ failed_conditions: type: list sample: ['...', '...'] """ +import re import time from ansible.module_utils.network.ios.ios import run_commands @@ -156,13 +157,14 @@ def parse_commands(module, warnings): ), module) commands = command(module.params['commands']) for item in list(commands): + configure_type = re.match(r'conf(?:\w*)(?:\s+(\w+))?', item['command']) if module.check_mode and not item['command'].startswith('show'): warnings.append( 'only show commands are supported when using check mode, not ' 'executing `%s`' % item['command'] ) commands.remove(item) - elif item['command'].startswith('conf'): + elif configure_type and configure_type.group(1) not in ('confirm', 'replace', 'revert', 'network'): module.fail_json( msg='ios_command does not support running config mode ' 'commands. Please use ios_config instead' diff --git a/test/units/modules/network/ios/fixtures/configure_revert_now b/test/units/modules/network/ios/fixtures/configure_revert_now new file mode 100644 index 0000000000..a112640904 --- /dev/null +++ b/test/units/modules/network/ios/fixtures/configure_revert_now @@ -0,0 +1,2 @@ +%No Rollback Confirmed Change pending + diff --git a/test/units/modules/network/ios/test_ios_command.py b/test/units/modules/network/ios/test_ios_command.py index 45a8ddabdd..6b9249eea8 100644 --- a/test/units/modules/network/ios/test_ios_command.py +++ b/test/units/modules/network/ios/test_ios_command.py @@ -106,3 +106,17 @@ class TestIosCommandModule(TestIosModule): commands = ['show version', 'show version'] set_module_args(dict(commands=commands, wait_for=wait_for, match='all')) self.execute_module(failed=True) + + def test_ios_command_configure_error(self): + commands = ['configure terminal'] + set_module_args(dict(commands=commands)) + result = self.execute_module(failed=True) + self.assertEqual( + result['msg'], + 'ios_command does not support running config mode commands. Please use ios_config instead' + ) + + def test_ios_command_configure_not_error(self): + commands = ['configure revert now'] + set_module_args(dict(commands=commands)) + self.execute_module()