diff --git a/lib/ansible/module_utils/ios.py b/lib/ansible/module_utils/ios.py index a449bc29bf..18f85fd170 100644 --- a/lib/ansible/module_utils/ios.py +++ b/lib/ansible/module_utils/ios.py @@ -47,6 +47,7 @@ def get_config(module, flags=[]): def run_commands(module, commands, check_rc=True): responses = list() for cmd in to_list(commands): + cmd = module.jsonify(cmd) rc, out, err = module.exec_command(cmd) if check_rc and rc != 0: module.fail_json(msg=err, rc=rc) diff --git a/lib/ansible/modules/network/eos/eos_command.py b/lib/ansible/modules/network/eos/eos_command.py index 3c00e715b4..e58d6ee4f8 100644 --- a/lib/ansible/modules/network/eos/eos_command.py +++ b/lib/ansible/modules/network/eos/eos_command.py @@ -165,14 +165,14 @@ def to_lines(stdout): return lines def parse_commands(module, warnings): - cast = ComplexList(dict( + transform = ComplexList(dict( command=dict(key=True), output=dict(), prompt=dict(), response=dict() )) - commands = cast(module.params['commands']) + commands = transform(module.params['commands']) for index, item in enumerate(commands): if module.check_mode and not item['command'].startswith('show'): @@ -180,6 +180,7 @@ def parse_commands(module, warnings): 'Only show commands are supported when using check_mode, not ' 'executing %s' % item['command'] ) + return commands def to_cli(obj): @@ -223,8 +224,6 @@ def main(): interval = module.params['interval'] match = module.params['match'] - commands = [to_cli(c) for c in commands] - while retries > 0: responses = run_commands(module, commands) diff --git a/lib/ansible/modules/network/ios/ios_command.py b/lib/ansible/modules/network/ios/ios_command.py index 3f85db46e3..c5121fb809 100644 --- a/lib/ansible/modules/network/ios/ios_command.py +++ b/lib/ansible/modules/network/ios/ios_command.py @@ -188,7 +188,6 @@ def parse_commands(module, warnings): response=dict() )) commands = command(module.params['commands']) - for index, item in enumerate(commands): if module.check_mode and not item['command'].startswith('show'): warnings.append( @@ -200,7 +199,6 @@ def parse_commands(module, warnings): msg='ios_command does not support running config mode ' 'commands. Please use ios_config instead' ) - commands[index] = module.jsonify(item) return commands def main(): diff --git a/test/units/modules/network/eos/test_eos_command.py b/test/units/modules/network/eos/test_eos_command.py index 30683630ea..ef372bf62a 100644 --- a/test/units/modules/network/eos/test_eos_command.py +++ b/test/units/modules/network/eos/test_eos_command.py @@ -72,10 +72,10 @@ class test_EosCommandModule(unittest.TestCase): for item in commands: try: - obj = json.loads(item) + obj = json.loads(item['command']) command = obj['command'] except ValueError: - command = item + command = item['command'] filename = str(command).replace(' ', '_') filename = 'eos_command_%s.txt' % filename output.append(load_fixture(filename)) diff --git a/test/units/modules/network/ios/test_ios_command.py b/test/units/modules/network/ios/test_ios_command.py index a22ae578c3..d1260fb3c4 100644 --- a/test/units/modules/network/ios/test_ios_command.py +++ b/test/units/modules/network/ios/test_ios_command.py @@ -72,10 +72,10 @@ class test_iosCommandModule(unittest.TestCase): for item in commands: try: - obj = json.loads(item) + obj = json.loads(item['command']) command = obj['command'] except ValueError: - command = item + command = item['command'] filename = str(command).replace(' ', '_') output.append(load_fixture(filename)) return output