community.routeros.command 模块 – 在运行 MikroTik RouterOS 的远程设备上运行命令
注意
此模块是 community.routeros 集合(版本 3.1.0)的一部分。
如果您使用的是 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.routeros。
要在 playbook 中使用它,请指定:community.routeros.command。
概要
- 将任意命令发送到 RouterOS 节点,并返回从设备读取的结果。此模块包含一个参数,该参数将导致模块等待特定条件满足,然后再返回;如果条件未满足,则超时。 
- 该模块始终指示(已更改)状态。您可以使用 changed_when 任务属性来确定命令任务是否真的导致了更改。 
参数
| 参数 | 注释 | 
|---|---|
| 通过配置的提供程序发送到远程 RouterOS 设备的命令列表。返回命令的输出结果。如果提供了  | |
| 配置命令重试之间等待的秒数间隔。如果命令未通过指定的条件,则间隔指示在再次尝试命令之前等待多长时间。 默认值:  | |
| 指定在认为命令失败之前应尝试的重试次数。每次重试都会在目标设备上运行该命令,并根据  默认值:  | |
| 要针对命令输出评估的条件列表。任务将等待每个条件为真,然后再继续执行。如果在配置的重试次数内条件不为真,则任务将失败。请参阅示例。 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持: 无 在 community.routeros 3.0.0 之前,该模块声称支持检查模式。它只是在检查模式下执行命令。 | 可以在  | |
| 支持: 无 | 当处于差异模式时,将返回有关已更改的内容(或在  | |
| 平台: RouterOS | 可以对其进行操作的目标操作系统/系列。 | 
参见
参见
- 如何使用 SSH 连接到 RouterOS 设备
- 如何使用 SSH 连接到 RouterOS 设备 
- 如何引用和取消引用命令和参数
- 如何引用和取消引用命令和参数 
示例
- name: Run command on remote devices
  community.routeros.command:
    commands: /system routerboard print
- name: Run command and check to see if output contains routeros
  community.routeros.command:
    commands: /system resource print
    wait_for: result[0] contains MikroTik
- name: Run multiple commands on remote nodes
  community.routeros.command:
    commands:
      - /system routerboard print
      - /system identity print
- name: Run multiple commands and evaluate the output
  community.routeros.command:
    commands:
      - /system routerboard print
      - /interface ethernet print
    wait_for:
      - result[0] contains x86
      - result[1] contains ether1
返回值
通用返回值记录在这里,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 失败的条件列表 返回: 失败 示例:  | |
| 来自命令的响应集合 返回: 总是返回,除了底层错误(例如操作插件) 示例:  | |
| stdout 的值拆分为列表 返回: 总是返回,除了底层错误(例如操作插件) 示例:  | 
