community.routeros.command 模块 – 在运行 MikroTik RouterOS 的远程设备上运行命令
注意
此模块是 community.routeros 集合(版本 3.1.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了这个集合。 它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.routeros
。
要在剧本中使用它,请指定:community.routeros.command
。
概要
向 RouterOS 节点发送任意命令,并返回从设备读取的结果。此模块包含一个参数,该参数将导致模块等待特定条件,然后再返回或超时(如果未满足条件)。
该模块始终指示(已更改)状态。 您可以使用 changed_when 任务属性 来确定命令任务是否实际导致了更改。
参数
参数 |
注释 |
---|---|
通过配置的提供程序发送到远程 RouterOS 设备的命令列表。返回命令的输出结果。如果提供了 |
|
配置命令重试之间等待的间隔(以秒为单位)。如果命令未通过指定的条件,则间隔表示再次尝试该命令之前等待的时间。 默认值: |
|
指定在认为命令失败之前应尝试的重试次数。每次重试都会在目标设备上运行该命令,并根据 默认值: |
|
要根据命令输出评估的条件列表。 任务将等待每个条件为真,然后再继续。如果在配置的重试次数内条件不为真,则任务失败。请参阅示例。 |
属性
属性 |
支持 |
描述 |
---|---|---|
支持: 无 在 community.routeros 3.0.0 之前,该模块声称支持检查模式。它只是在检查模式下执行命令。 |
可以在 |
|
支持: 无 |
当处于 diff 模式时,将返回有关已更改的内容(或可能需要在 |
|
平台: 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
返回值
常见的返回值在 此处 记录,以下是此模块特有的字段
键 |
描述 |
---|---|
失败的条件列表 返回: failed 示例: |
|
来自命令的响应集合 返回: 始终返回,除非发生底层错误(例如操作插件) 示例: |
|
将 stdout 的值拆分为列表 返回: 始终返回,除非发生底层错误(例如操作插件) 示例: |