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

Fallback to text when json is not supported #747

Open
xibriz opened this issue Sep 7, 2023 · 3 comments
Open

Fallback to text when json is not supported #747

xibriz opened this issue Sep 7, 2023 · 3 comments
Assignees
Labels
waiting_on_contributor Waiting on community contribution and PR

Comments

@xibriz
Copy link

xibriz commented Sep 7, 2023

I have a Nexus 5596 with NXOS 7.0(2)N1(1)

When trying to gather facts ansible_net_interfaces does not get populated correctly.

Further investigating shows that the command show interface | json-pretty is not supported. The device does not have any json capabilities.

It seems like some sort of text fallback is missing in the run-function.

def run(self, command, output="text"):
command_string = command
if output == "json":
# Not all devices support | json-pretty but is a workaround for
# libssh issue https://github.com/ansible/pylibssh/issues/208
output = "json-pretty"
resp = []
command = {"command": command, "output": output}
try:
resp = run_commands(self.module, [command], check_rc="retry_json")
except Exception:
if output == "json-pretty":
# reattempt with | json
resp = run_commands(
self.module,
[{"command": command, "output": "json"}],
check_rc="retry_json",
)
try:
return resp[0]
except IndexError:
self.warnings.append(
"command %s failed, facts for this command will not be populated" % command_string,
)
return None

I have temporarly solved the problem by adding the following code:

# Fallback to text
if isinstance(resp, list) and len(resp) > 0 and 'Invalid command at' in resp[0] and output != "text":
    command["output"] = "text"
    resp = run_commands(self.module, [command], check_rc="retry_json")
Software
  BIOS:      version 3.6.0
  loader:    version N/A
  kickstart: version 7.0(2)N1(1)
  system:    version 7.0(2)N1(1)
  Power Sequencer Firmware: 
             Module 1: version v7.0
             Module 2: version v1.0
             Module 3: version v0.0
             Module 4: version v0.0
  Microcontroller Firmware:        version v1.0.0.2
  SFP uC:    Module 1: v1.0.0.0
  QSFP uC:   Module not detected
  BIOS compile time:       05/09/2012
  kickstart image file is: bootflash:///n5000-uk9-kickstart.7.0.2.N1.1.bin
  kickstart compile time:  5/1/2014 23:00:00 [05/02/2014 09:01:22]
  system image file is:    bootflash:///n5000-uk9.7.0.2.N1.1.bin
  system compile time:     5/1/2014 23:00:00 [05/02/2014 12:48:49]


Hardware
  cisco Nexus 5596 Chassis ("O2 48X10GE/Modular Supervisor")
  Intel(R) Xeon(R) CPU         with 8253860 kB of memory.
  Processor Board ID FOC15482JC8
@NilashishC NilashishC self-assigned this Sep 7, 2023
@NilashishC NilashishC added the bug This issue/PR relates to a bug. label Sep 7, 2023
@NilashishC
Copy link
Collaborator

NilashishC commented Sep 7, 2023

@xibriz Thank you for reporting this. Do you mean that your target device does not support any form of | json output?

Also, please note that the chassis and NX-OS combination you shared is not a part of our platform support matrix and hence, fixing this issue will be on a best effort basis.

Ref: https://docs.ansible.com/ansible/latest/network/user_guide/platform_nxos.html#cisco-nexus-platform-support-matrix

Thank you.

@xibriz
Copy link
Author

xibriz commented Sep 8, 2023

@NilashishC Yes, that is correct, see the output below.

You know the collection best, but I (and probably others) would be happy with a more robust solution of my fix, or some kind of option in the facts module to force text output in stead of json.

Since the rest of the code handles text output as well as json, this should be possible without breaking anything?

HOSTNAME# show interface | ?
  cut      Print selected parts of lines.
  diff     Show difference between current and previous invocation (creates temp files: remove them with 'diff-clean' command and dont use it on commands with big
           outputs, like 'show tech'!) 
  egrep    Egrep - print lines matching a pattern
  grep     Grep - print lines matching a pattern
  head     Display first lines
  human    Output in human format
  last     Display last lines
  less     Filter for paging
  no-more  Turn-off pagination for command output
  section  Show lines that include the pattern as well as the subsequent lines that are more indented than matching line
  sort     Stream Sorter
  source   Run a script (python, tcl,...) from bootflash:scripts
  tr       Translate, squeeze, and/or delete characters
  uniq     Discard all but one of successive identical lines
  vsh      The shell that understands cli command
  wc       Count words, lines, characters
  xml      Output in xml format (according to .xsd definitions)
  begin    Begin with the line that matches
  count    Count number of lines
  end      End with the line that matches
  exclude  Exclude lines that match
  include  Include lines that match

@NilashishC NilashishC added the waiting_on_contributor Waiting on community contribution and PR label Jan 16, 2024
@NilashishC
Copy link
Collaborator

Considering the substantial effort involved and the fact that NX-OS versions lacking support for | json fall outside our current support scope, we've made the decision not to pursue this implementation. However, we strongly encourage contributions from the community! If anyone is enthusiastic about tackling this challenge, we'd be delighted to accept and review their contributions. As such, I've added the waiting_on_contributor label to this. Should a pull request be submitted, we'll review and collaborate on moving it forward together.

Thank you!

@NilashishC NilashishC removed the bug This issue/PR relates to a bug. label Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting_on_contributor Waiting on community contribution and PR
Projects
None yet
Development

No branches or pull requests

2 participants