首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么Mellanox 'onyx_interface‘模块失败了?

为什么Mellanox 'onyx_interface‘模块失败了?
EN

Stack Overflow用户
提问于 2022-09-20 16:46:35
回答 2查看 38关注 0票数 1

我的Mellanox任务角色:

代码语言:javascript
复制
---
- 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

我的剧本:

代码语言:javascript
复制
---
- hosts: mellanox_switch
  gather_facts: no
  roles:
    - mellanox

它产生的错误(冗长的3):

代码语言:javascript
复制
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] > "
}

奇怪的是,onyx_command模块工作得很好:

代码语言:javascript
复制
---
# Mellanox management
- name: set mellanox
  set_fact:
    ansible_network_os: 'onyx'
    ansible_connection: network_cli

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

不知道是什么问题。我想这可能和安装有关。

EN

回答 2

Stack Overflow用户

发布于 2022-09-20 17:28:32

需要将下列行添加到剧本中

代码语言:javascript
复制
  become: yes
  become_method: enable
票数 1
EN

Stack Overflow用户

发布于 2022-09-20 17:29:43

为什么Mellanox onyx_interface模块失败了?

根据错误信息

代码语言:javascript
复制
show version | json-print
Unrecognized command "json-print"

原因似乎与模块源代码module_utils/network/onyx/onyx.py有关。

社区收藏Mellanox Onyx模块模块管理Mellanox ONYX网络设备上的接口将从他自己的模块实用程序中导入(参见modules/onyx_interface)

代码语言:javascript
复制
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

并尝试查找远程设备的版本和功能。

它尝试将结果输出格式化为JSON

代码语言:javascript
复制
def show_cmd(module, cmd, json_fmt=True, fail_on_error=True):
    if json_fmt:
        cmd += " | json-print"
    conn = get_connection(module)

这个特定的命令| json-print不是在远程设备上不可用,就是没有功能,或者缺少权限。这也解释了为什么命令show version只起作用。

若要缩小原因,还应尝试执行

代码语言:javascript
复制
---

# 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73790068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档