Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail on configure in command (#37011) #37094

Merged
merged 1 commit into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions lib/ansible/modules/network/ios/ios_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 4 additions & 1 deletion test/units/modules/network/ios/test_ios_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def test_ios_command_match_all_failure(self):

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'],
Expand Down