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

Fix nxos_banner module for unstructured output #36411

Merged
merged 3 commits into from
Feb 21, 2018
Merged
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
22 changes: 21 additions & 1 deletion lib/ansible/modules/network/nxos/nxos_banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@
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']
Expand All @@ -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")
Expand All @@ -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:
Expand Down