Fix nxos_banner module for unstructured output (#36411)
* Fix nxos_banner module for unstructured output * Refactor and bug fixes * Fix pep8 error
This commit is contained in:
parent
2bffcfa63b
commit
ef7d574920
1 changed files with 21 additions and 1 deletions
|
@ -94,6 +94,23 @@ from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_arg
|
|||
import re
|
||||
|
||||
|
||||
def execute_show_command(module, command):
|
||||
format = 'json'
|
||||
cmds = [{
|
||||
'command': command,
|
||||
'output': format,
|
||||
}]
|
||||
output = run_commands(module, cmds, False)
|
||||
if len(output) == 0 or len(output[0]) == 0:
|
||||
# If we get here the platform does not
|
||||
# support structured output. Resend as
|
||||
# text.
|
||||
cmds[0]['output'] = 'text'
|
||||
output = run_commands(module, cmds, False)
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
state = module.params['state']
|
||||
|
@ -111,7 +128,8 @@ def map_obj_to_commands(want, have, module):
|
|||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
output = run_commands(module, ['show banner %s' % module.params['banner']], False)[0]
|
||||
command = 'show banner %s' % module.params['banner']
|
||||
output = execute_show_command(module, command)[0]
|
||||
|
||||
if "Invalid command" in output:
|
||||
module.fail_json(msg="banner: exec may not be supported on this platform. Possible values are : exec | motd")
|
||||
|
@ -128,6 +146,8 @@ def map_config_to_obj(module):
|
|||
output = output[0]
|
||||
else:
|
||||
output = ''
|
||||
else:
|
||||
output = output.rstrip()
|
||||
|
||||
obj = {'banner': module.params['banner'], 'state': 'absent'}
|
||||
if output:
|
||||
|
|
Loading…
Reference in a new issue