mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Don't fail on configure in command (#37011)
* Don't fail on configure in command * Change test to check mode
This commit is contained in:
parent
67ffde4ac1
commit
efb8b539c1
2 changed files with 16 additions and 12 deletions
|
@ -166,17 +166,18 @@ def parse_commands(module, warnings):
|
||||||
commands = command(module.params['commands'])
|
commands = command(module.params['commands'])
|
||||||
for item in list(commands):
|
for item in list(commands):
|
||||||
configure_type = re.match(r'conf(?:\w*)(?:\s+(\w+))?', item['command'])
|
configure_type = re.match(r'conf(?:\w*)(?:\s+(\w+))?', item['command'])
|
||||||
if module.check_mode and not item['command'].startswith('show'):
|
if module.check_mode:
|
||||||
warnings.append(
|
if configure_type and configure_type.group(1) not in ('confirm', 'replace', 'revert', 'network'):
|
||||||
'only show commands are supported when using check mode, not '
|
module.fail_json(
|
||||||
'executing `%s`' % item['command']
|
msg='ios_command does not support running config mode '
|
||||||
)
|
'commands. Please use ios_config instead'
|
||||||
commands.remove(item)
|
)
|
||||||
elif configure_type and configure_type.group(1) not in ('confirm', 'replace', 'revert', 'network'):
|
if not item['command'].startswith('show'):
|
||||||
module.fail_json(
|
warnings.append(
|
||||||
msg='ios_command does not support running config mode '
|
'only show commands are supported when using check mode, not '
|
||||||
'commands. Please use ios_config instead'
|
'executing `%s`' % item['command']
|
||||||
)
|
)
|
||||||
|
commands.remove(item)
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,10 @@ class TestIosCommandModule(TestIosModule):
|
||||||
|
|
||||||
def test_ios_command_configure_error(self):
|
def test_ios_command_configure_error(self):
|
||||||
commands = ['configure terminal']
|
commands = ['configure terminal']
|
||||||
set_module_args(dict(commands=commands))
|
set_module_args({
|
||||||
|
'commands': commands,
|
||||||
|
'_ansible_check_mode': True,
|
||||||
|
})
|
||||||
result = self.execute_module(failed=True)
|
result = self.execute_module(failed=True)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
result['msg'],
|
result['msg'],
|
||||||
|
|
Loading…
Reference in a new issue