ios_command: Whitelist some commands starting with configure (#35363)

* Whitelist some commands starting with `configure`

* Add tests for conditional `configure` rejection
This commit is contained in:
Nathaniel Case 2018-01-26 10:55:50 -05:00 committed by GitHub
commit 1f1e5c11a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -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'