Ansible | Why is the Mellanox 'onyx_interface' module failing?

Viewed 29

My Mellanox task role:

---
- name: set mellanox
  set_fact:
    ansible_network_os: 'onyx'
    ansible_connection: network_cli

- name: configure interface Eth1/2
  mellanox.onyx.onyx_interface:
    name: Eth1/2
    mtu: 1500

My playbook:

---
- hosts: mellanox_switch
  gather_facts: no
  roles:
    - mellanox

The error (verbose 3) it produces:

The full traceback is:
  File "/tmp/ansible_mellanox.onyx.onyx_interface_payload_8h8n_8qc/ansible_mellanox.onyx.onyx_interface_payload.zip/ansible_collections/mellanox/onyx/plugins/module_utils/network/onyx/onyx.py", line 158, in get_capabilities
    capabilities = connection.get_capabilities()
  File "/tmp/ansible_mellanox.onyx.onyx_interface_payload_8h8n_8qc/ansible_mellanox.onyx.onyx_interface_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [192.168.1.4]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "aggregate": null,
            "delay": 10,
            "description": null,
            "enabled": null,
            "mtu": 1500,
            "name": "Eth1/2",
            "purge": false,
            "rx_rate": null,
            "speed": null,
            "state": "present",
            "tx_rate": null
        }
    },
    "msg": "show version | json-print\r\r\n% Unrecognized command \"json-print\".\r\nType \"?\" for help.\r\n\r [standalone: master] > "
}

What is odd, is that the onyx_command module works just fine:

---
# Mellanox management
- name: set mellanox
  set_fact:
    ansible_network_os: 'onyx'
    ansible_connection: network_cli

- name: test show version
  onyx_command:
    commands: show version

Not sure what the issue is. Thinking it might be installation related.

2 Answers

Needed to add the following lines to the playbook

  become: yes
  become_method: enable

Why is the Mellanox onyx_interface module is failing?

According the error message

show version | json-print
Unrecognized command "json-print"

the reason seems to be somehow related to the module source code module_utils/network/onyx/onyx.py.

The Community Collection Mellanox Onyx module onyx_interface module – Manage Interfaces on Mellanox ONYX network devices will import from his own module utilities (see modules/onyx_interface)

from ansible_collections.mellanox.onyx.plugins.module_utils.network.onyx.onyx import BaseOnyxModule
from ansible_collections.mellanox.onyx.plugins.module_utils.network.onyx.onyx import get_interfaces_config

and try to find the version and capabilities of the Remote Device.

It tries to format the result output to JSON according

def show_cmd(module, cmd, json_fmt=True, fail_on_error=True):
    if json_fmt:
        cmd += " | json-print"
    conn = get_connection(module)

That specific command | json-print is either not available on the Remote Device, there are no capabilities for, or rights are missing. This explains also why the command show version only was working.

To narrow down the cause you should also try to execute

---

# Mellanox management

- name: Address Mellanox environment 
  set_fact:
    ansible_network_os: 'onyx'
    ansible_connection: network_cli

- name: Test 'show version'
  onyx_command:
    commands: show version | json-print
  register: result

- name: Show result
  debug:
    var: result
Related