win_netroute

win_netroute - Adds or removes an IP route in the IP routing table

Synopsis

  • Ansible module to add or remove an IP route in the IP routing table on Windows-based systems.

Parameters

Parameter Choices/Defaults Comments
interface_alias
string
Alias of a network interface.
The module adds or removes a route for the interface that has the alias that you specify.
If interface_alias is not provided and gateway is provided, the module uses the [Find-NetRoute] cmdlet to determine the value of interface_alias.
destination
string / required
Destination IP address in CIDR format (ip address/prefix length).
gateway
string
Gateway used by the static route.
If gateway and interface_alias are not provided it will be set to 0.0.0.0.
If gateway is not provided it will be set to the gateway defined for interface_alias.
metric
integer
Default:
1
Metric used by the static route.
state
string
Choices:
  • absent
  • present ←
If absent, it removes a network static route.
If present, it adds a network static route.

Examples

---
---
  roles:
    - win_netroute

  tasks:

    - name: Add a network static route
      win_netroute:
        interface_alias: eth1
        destination: 192.168.2.10/32
        gateway: 192.168.1.1
        metric: 1
        state: present

    - name: Add a network static route by using the gateway of the network interface
      win_netroute:
        interface_alias: eth1
        destination: 192.168.2.10/32
        metric: 1
        state: present

    - name: Add a network static route by using 0.0.0.0 as gateway
      win_netroute:
        destination: 192.168.2.10/32
        metric: 1
        state: present

    - name: Remove a network static route by using the gateway
      win_netroute:
        destination: 192.168.2.10/32
        state: absent
        gateway: 192.168.1.1

    - name: Remove a network static route by using the interface alias
      win_netroute:
        interface_alias: eth1
        destination: 192.168.2.10/32
        state: absent

    - name: Remove a network static route
      win_netroute:
        destination: 192.168.2.10/32
        state: absent

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
destination
string
always The destination IP address in CIDR format.

Sample:
192.168.2.10/32
gateway
string
always The gateway used by the static route.

Sample:
192.168.1.1
interface_alias
string
always The alias of a network interface used for the static route.

Sample:
eth1
metric
integer
always The metric used by the static route.

Sample:
16
output
string
always A message describing the task result.

Sample:
Route added
state
string
always The state of the IP route.

Sample:
present

Notes

  • Works only with Windows 2012 R2 and newer.
  • This module is a fork of the [win_route] module.
  • This module allows to add or remove a route for the interface that has the alias that you specify.
  • This module automatically calculates the gateway as a network interface when it does not have one by default.
  • This module allows you to modify the characteristics of a route that already exists (metric, gateway or interface).

Authors

  • Stéphane Bilqué (@sbilque) - fork of win_route
  • Daniele Lazzari (lazzari@mailup.com)- creator of win_route

License

This project is licensed under the GNU General Public License v3.0 License.

See LICENSE to see the full text.

About

Adds or removes an IP route in the IP routing table

Install
ansible-galaxy install informatique-cdc/ansible-role-win_netroute
GitHub repository
License
gpl-3.0
Downloads
25
Owner
Informatique CDC, subsidiary of Group Caisse des Dépôts is a key player in IT services and digital trust.