community.windows.win_route 模块 – 添加或删除静态路由

注意

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

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

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

要在剧本中使用它,请指定:community.windows.win_route

概要

  • 添加或删除静态路由。

参数

参数

注释

destination

字符串 / 必填

以 CIDR 格式表示的目标 IP 地址(IP 地址/前缀长度)。

gateway

字符串

静态路由使用的网关。

如果未提供 gateway,它将设置为 0.0.0.0

metric

整数

静态路由使用的度量。

默认值: 1

state

字符串

如果为 absent,则删除网络静态路由。

如果为 present,则添加网络静态路由。

选项

  • "absent"

  • "present" ← (默认)

备注

注意

  • 仅适用于 Windows 2012 R2 及更高版本。

示例

---
- name: Add a network static route
  community.windows.win_route:
    destination: 192.168.2.10/32
    gateway: 192.168.1.1
    metric: 1
    state: present

- name: Remove a network static route
  community.windows.win_route:
    destination: 192.168.2.10/32
    state: absent

返回值

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

描述

output

字符串

描述任务结果的消息。

返回:始终

示例: "Route added"

作者

  • Daniele Lazzari (@dlazz)