community.routeros.api_facts 模块 – 使用 API 从运行 MikroTik RouterOS 的远程设备收集事实

注意

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

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

要安装它,请使用: ansible-galaxy collection install community.routeros。您需要其他需求才能使用此模块,有关详细信息,请参阅 需求

要在剧本中使用它,请指定: community.routeros.api_facts

community.routeros 2.1.0 中的新增功能

概要

  • 从运行 RouterOS 的远程设备收集一组基本设备事实。此模块将所有基本网络事实键名前缀为 ansible_net_<fact>。事实模块将始终从设备收集一组基本事实,并且可以启用或禁用其他事实的收集。

  • community.routeros.facts 模块相反,它使用 RouterOS API,类似于 community.routeros.api 模块。

需求

执行此模块的主机需要以下需求。

  • librouteros

  • Python >= 3.6 (适用于 librouteros)

参数

参数

注释

ca_path

路径

在 community.routeros 1.2.0 中添加

包含用于证书验证的 CA 证书的 PEM 格式文件。

另请参阅 validate_cert_hostname。仅当 tls=truevalidate_certs=true 时使用。

encoding

字符串

在 community.routeros 2.1.0 中添加

与 RouterOS 设备通信时使用指定的编码。

默认为 ASCII。请注意,UTF-8 需要 librouteros 3.2.1 或更高版本。

默认值: "ASCII"

force_no_cert

布尔值

在 community.routeros 2.4.0 中添加

设置为 true 以在 tls=true 时无需证书即可连接。

另请参阅 validate_certs

注意:这强制使用匿名 Diffie-Hellman (ADH) 密码。该协议容易受到中间人攻击,因为交换中使用的密钥未经身份验证。与其简单地不使用证书连接以“使事情正常工作”,不如查看 validate_certsca_path

选项

  • false ← (默认)

  • true

gather_subset

列表 / 元素=字符串

提供此参数时,它会将收集的事实限制为给定的子集。此参数的可能值为 allhardwareinterfacesrouting

可以指定一个值列表以包含更大的子集。值也可以与初始 ! 一起使用,以指定不应收集特定子集。

默认值: ["all"]

hostname

字符串 / 必需

RouterOS 主机名 API。

password

字符串 / 必需

RouterOS 用户密码。

port

整数

RouterOS api 端口。如果设置了 tls,则端口将应用于 TLS/SSL 连接。

HTTP API 的默认值为 8728,HTTPS API 的默认值为 8729

timeout

整数

在 community.routeros 2.3.0 中添加

请求超时。

默认值: 10

tls

别名:ssl

布尔值

如果设置,则将使用 TLS 进行 RouterOS API 连接。

选项

  • false ← (默认)

  • true

username

字符串 / 必需

RouterOS 登录用户。

validate_cert_hostname

布尔值

在 community.routeros 1.2.0 中添加

设置为 true 以验证证书中的主机名。

另见 validate_certs。仅当 tls=truevalidate_certs=true 时使用。

选项

  • false ← (默认)

  • true

validate_certs

布尔值

在 community.routeros 1.2.0 中添加

设置为 false 以跳过 TLS 证书验证。

另见 validate_cert_hostname。仅当 tls=true 时使用。

注意: 请勿仅仅为了“使程序运行”而禁用证书验证,请考虑创建您自己的 CA 证书并使用它来签署用于路由器的证书。您可以使用 ca_path 选项将您的 CA 证书告知模块。

选项

  • false

  • true ← (默认)

属性

属性

支持

描述

action_group

动作组: community.routeros.api

module_defaults 中使用 group/community.routeros.api 为此模块设置默认值。

check_mode

支持: 完全支持

此操作不会修改状态。

可以在 check_mode 下运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持: N/A

此操作不会修改状态。

在差异模式下,将返回有关已更改内容(或可能需要在 check_mode 中更改的内容)的详细信息。

facts

支持: 完全支持

操作返回一个 ansible_facts 字典,该字典将更新现有的主机事实。

platform

平台: RouterOS

可以对其进行操作的目标操作系统/系列。

另见

另见

community.routeros.facts

收集运行 MikroTik RouterOS 的远程设备的事实。

community.routeros.api

用于 RouterOS API 的 Ansible 模块。

community.routeros.api_find_and_modify

使用 API 查找和修改信息。

community.routeros.api_info

从 API 获取信息。

community.routeros.api_modify

使用 API 修改路径中的数据。

如何使用 RouterOS API 连接到 RouterOS 设备

如何使用 RouterOS API 连接到 RouterOS 设备

示例

- name: Collect all facts from the device
  community.routeros.api_facts:
    hostname: 192.168.88.1
    username: admin
    password: password
    gather_subset: all

- name: Do not collect hardware facts
  community.routeros.api_facts:
    hostname: 192.168.88.1
    username: admin
    password: password
    gather_subset:
      - "!hardware"

返回的事实

此模块返回的事实会添加到 hostvars 主机事实中/更新 hostvars 主机事实,并且可以像任何其他主机事实一样按名称引用它们。无需注册即可使用它们。

描述

ansible_net_all_ipv4_addresses

列表 / 元素=字符串

设备上配置的所有 IPv4 地址。

返回: gather_subset 包含 interfaces

ansible_net_all_ipv6_addresses

列表 / 元素=字符串

设备上配置的所有 IPv6 地址。

返回: gather_subset 包含 interfaces

ansible_net_arch

字符串

设备的 CPU 架构。

返回: gather_subset 包含 default

ansible_net_bgp_instance

字典

包含 BGP 实例信息的字典。

返回: gather_subset 包含 routing

ansible_net_bgp_peer

字典

包含 BGP 对等体信息的字典。

返回: gather_subset 包含 routing

ansible_net_bgp_vpnv4_route

字典

包含 BGP vpnv4 路由信息的字典。

返回: gather_subset 包含 routing

ansible_net_cpu_load

字符串

当前 CPU 负载。

返回: gather_subset 包含 default

ansible_net_gather_subset

列表 / 元素=字符串

从设备收集的事实子集列表。

返回: 始终返回

ansible_net_hostname

字符串

设备的配置主机名。

返回: gather_subset 包含 default

ansible_net_interfaces

字典

系统上运行的所有接口的哈希表。

返回: gather_subset 包含 interfaces

ansible_net_memfree_mb

整数

远程设备上可用的空闲内存(以 MiB 为单位)。

返回: gather_subset 包含 hardware

ansible_net_memtotal_mb

整数

远程设备上的总内存(以 MiB 为单位)。

返回: gather_subset 包含 hardware

ansible_net_model

字符串

设备返回的型号名称。

返回: gather_subset 包含 default

ansible_net_neighbors

字典

远程设备的邻居列表。

返回: gather_subset 包含 interfaces

ansible_net_ospf_instance

字典

包含 OSPF 实例的字典。

返回: gather_subset 包含 routing

ansible_net_ospf_neighbor

字典

包含 OSPF 邻居的字典。

返回: gather_subset 包含 routing

ansible_net_route

字典

所有路由表中路由的字典。

返回: gather_subset 包含 routing

ansible_net_serialnum

字符串

远程设备的序列号。

返回: gather_subset 包含 default

ansible_net_spacefree_mb

字典

远程设备上可用的磁盘空间(以 MiB 为单位)。

返回: gather_subset 包含 hardware

ansible_net_spacetotal_mb

字典

远程设备上的总磁盘空间(以 MiB 为单位)。

返回: gather_subset 包含 hardware

ansible_net_uptime

字符串

设备的运行时间。

返回: gather_subset 包含 default

ansible_net_version

字符串

远程设备上运行的操作系统版本。

返回: gather_subset 包含 default

作者

  • Egor Zaitsev (@heuels)

  • Nikolay Dachev (@NikolayDachev)

  • Felix Fontein (@felixfontein)