community.network.nos_command 模块 – 在运行 Extreme Networks NOS 的远程设备上运行命令

注意

此模块是 community.network 集合(版本 5.1.0)的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.network

要在剧本中使用它,请指定:community.network.nos_command

注意

community.network 集合已被弃用,将从 Ansible 12 中删除。有关更多信息,请参阅讨论线程

已弃用

在以下版本中删除:

版本 6.0.0

原因:

此集合及其中的所有内容均未维护且已弃用。

替代方案:

未知。

概要

  • 将任意命令发送到 NOS 设备并返回从设备读取的结果。此模块包含一个参数,该参数将使模块在返回之前等待特定条件,如果未满足条件,则超时。

  • 此模块不支持在配置模式下运行命令。请使用 community.network.nos_config 配置 NOS 设备。

别名:network.nos.nos_command

参数

参数

注释

命令

字符串 / 必需

通过配置的提供程序发送到远程 NOS 设备的命令列表。返回命令的结果输出。如果提供了 wait_for 参数,则在满足条件或重试次数过期之前,模块不会返回。

间隔

字符串

配置重试命令之间等待的间隔(以秒为单位)。如果命令未通过指定的条件,则间隔指示再次尝试该命令之前要等待的时间。

默认值: 1

匹配

字符串

match 参数与 wait_for 参数结合使用,以指定匹配策略。有效值为 allany。如果值设置为 all,则必须满足 wait_for 中的所有条件。如果值设置为 any,则只需满足其中一个值。

选项

  • "any"

  • "all" ← (默认)

重试次数

字符串

指定在被视为失败之前应尝试命令的重试次数。每次重试时,都会在目标设备上运行命令,并根据 wait_for 条件进行评估。

默认值: 10

等待

字符串

要针对命令输出评估的条件列表。任务将等待每个条件为真,然后才继续前进。如果在配置的重试次数内条件不为真,则任务将失败。请参阅示例。

注意

注意

  • 针对 NOS 7.2.0 进行了测试

  • 如果发送到设备的命令需要回答提示,则可以传递包含 commandanswerprompt 的字典。请参阅示例。

示例

tasks:
  - name: Run show version on remote devices
    community.network.nos_command:
      commands: show version

  - name: Run show version and check to see if output contains NOS
    community.network.nos_command:
      commands: show version
      wait_for: result[0] contains NOS

  - name: Run multiple commands on remote nodes
    community.network.nos_command:
      commands:
        - show version
        - show interfaces

  - name: Run multiple commands and evaluate the output
    community.network.nos_command:
      commands:
        - show version
        - show interface status
      wait_for:
        - result[0] contains NOS
        - result[1] contains Te
  - name: Run command that requires answering a prompt
    community.network.nos_command:
      commands:
        - command: 'clear sessions'
          prompt: 'This operation will logout all the user sessions. Do you want to continue (yes/no)?:'
          answer: y

返回值

常见的返回值记录在此处,以下是此模块特有的字段

描述

失败的条件

列表 / elements=字符串

失败的条件列表

已返回: 失败

示例: ["...", "..."]

标准输出

列表 / elements=字符串

来自命令的一组响应

返回: 总是返回,除非发生底层错误(例如 action 插件错误)

示例: ["...", "..."]

stdout_lines

列表 / elements=字符串

stdout 的值被分割成一个列表

返回: 总是返回,除非发生底层错误(例如 action 插件错误)

示例: [["...", "..."], ["..."], ["..."]]

状态

  • 此模块将在 6.0.0 版本中移除。[已弃用]

  • 更多信息请参见 已弃用

作者

  • Lindsay Hill (@LindsayHill)