summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Case <this.is@nathanielca.se>2018-03-06 18:24:43 -0500
committerGitHub <noreply@github.com>2018-03-06 18:24:43 -0500
commit2be960f84a813ffad3282df5d26287553686e9b1 (patch)
tree8c4af4c2549d8b8c7d71f192ebe0af6d9cc5bfd4
parentb1f8fd7edb131c49639a779f9147d591b7e445fa (diff)
downloadansible-2be960f84a813ffad3282df5d26287553686e9b1.tar.gz
Don't fail on configure in command (#37094)
* Don't fail on configure in command * Change test to check mode (cherry picked from commit efb8b539c1957f93b42b55bde7ff3cfa6ad2009d)
-rw-r--r--lib/ansible/modules/network/ios/ios_command.py23
-rw-r--r--test/units/modules/network/ios/test_ios_command.py5
2 files changed, 16 insertions, 12 deletions
diff --git a/lib/ansible/modules/network/ios/ios_command.py b/lib/ansible/modules/network/ios/ios_command.py
index dc606e0cb8..90d3f32c52 100644
--- a/lib/ansible/modules/network/ios/ios_command.py
+++ b/lib/ansible/modules/network/ios/ios_command.py
@@ -166,17 +166,18 @@ def parse_commands(module, warnings):
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 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'
- )
+ if module.check_mode:
+ if 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'
+ )
+ if not item['command'].startswith('show'):
+ warnings.append(
+ 'only show commands are supported when using check mode, not '
+ 'executing `%s`' % item['command']
+ )
+ commands.remove(item)
return commands
diff --git a/test/units/modules/network/ios/test_ios_command.py b/test/units/modules/network/ios/test_ios_command.py
index 6b9249eea8..68822d6a0b 100644
--- a/test/units/modules/network/ios/test_ios_command.py
+++ b/test/units/modules/network/ios/test_ios_command.py
@@ -109,7 +109,10 @@ class TestIosCommandModule(TestIosModule):
def test_ios_command_configure_error(self):
commands = ['configure terminal']
- set_module_args(dict(commands=commands))
+ set_module_args({
+ 'commands': commands,
+ '_ansible_check_mode': True,
+ })
result = self.execute_module(failed=True)
self.assertEqual(
result['msg'],