cisco.nxos.nxos_command 模块 – 在 Cisco NXOS 设备上运行任意命令
注意
此模块是 cisco.nxos 集合 (版本 9.2.1) 的一部分。
如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install cisco.nxos。
要在 playbook 中使用它,请指定: cisco.nxos.nxos_command。
cisco.nxos 1.0.0 中的新增功能
概要
- 将任意命令发送到 NXOS 节点并返回从设备读取的结果。此模块包含一个参数,该参数将使模块在返回之前等待特定条件,或者如果未满足条件则超时。 
参数
| 参数 | 注释 | 
|---|---|
| 要发送到远程 NXOS 设备的命令。返回命令的结果输出。如果提供了 *wait_for* 参数,则在满足条件或达到重试次数限制之前,模块不会返回。 *commands* 参数还接受另一种形式,允许指定要运行的命令和要返回的输出格式的复杂值。这可以在每个命令的基础上完成。复杂参数支持关键字  如果发送到设备的命令需要回答提示,则可以传递包含命令、答案和提示的字典。常见的答案是 'y' 或 “\r”(回车符,必须使用双引号)。请参见示例。 | |
| 配置以秒为单位的间隔,用于在命令重试之间等待。如果命令未通过指定的条件,则间隔表示在再次尝试命令之前等待的时间。 默认值:  | |
| *match* 参数与 *wait_for* 参数一起使用,用于指定匹配策略。有效值为  选项 
 | |
| 指定在命令被认为失败之前应尝试的重试次数。命令在每次重试时都在目标设备上运行,并根据 *wait_for* 条件进行评估。 当 *retries* 设置为  默认值:  | |
| 指定要从命令输出中评估的内容以及要应用的条件。此参数将导致任务在继续之前等待特定条件为真。如果在配置的重试次数内条件不为真,则任务失败。请参见示例。 | 
备注
注意
- 对 Cisco MDS 的有限支持 
- 有关使用 CLI 和 NX-API 的信息,请参阅:ref:`NXOS 平台选项指南 - ` 
- 有关使用 Ansible 管理网络设备的更多信息,请参阅:ref:`Ansible 网络指南 - ` 
- 有关使用 Ansible 管理 Cisco 设备的更多信息,请参阅 `Cisco 集成页面 <https://ansible.org.cn/integrations/networks/cisco>`_。 
示例
- name: run show version on remote devices
  cisco.nxos.nxos_command:
    commands: show version
- name: run show version and check to see if output contains Cisco
  cisco.nxos.nxos_command:
    commands: show version
    wait_for: result[0] contains Cisco
- name: run multiple commands on remote nodes
  cisco.nxos.nxos_command:
    commands:
      - show version
      - show interfaces
- name: run multiple commands and evaluate the output
  cisco.nxos.nxos_command:
    commands:
      - show version
      - show interfaces
    wait_for:
      - result[0] contains Cisco
      - result[1] contains loopback0
- name: run commands and specify the output format
  cisco.nxos.nxos_command:
    commands:
      - command: show version
        output: json
- name: run commands that require answering a prompt
  cisco.nxos.nxos_command:
    commands:
      - configure terminal
      - command: no feature npv
        prompt: Do you want to continue
        answer: y
返回值
常见的返回值在 此处 有记录,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 已失败的条件列表 返回:失败 示例:  | |
| 命令的响应集 返回:除了低级错误(例如操作插件)之外,始终返回 示例:  | |
| stdout 的值拆分为列表 返回:除了低级错误(例如操作插件)之外,始终返回 示例:  | 
