Fixed win_route module (#46395)

* Changed $IpAddress to $Gateway

* Tweaked win_route unit tests

Checks to see if new static route has the correct gateway

* Create win_route.yaml

* Fixed incorrect variable name
pull/49586/head
uberjew666 6 years ago committed by ansibot
parent a74449b05f
commit b72187cd2c

@ -0,0 +1,2 @@
bugfixes:
- win_route - Corrected issue where the wrong network interface was used for new static routes. - https://github.com/ansible/ansible/issues/28051

@ -39,7 +39,7 @@ Function Add-Route {
if (!($Route)){
try {
# Find Interface Index
$InterfaceIndex = Find-NetRoute -RemoteIPAddress $IpAddress | Select -First 1 -ExpandProperty InterfaceIndex
$InterfaceIndex = Find-NetRoute -RemoteIPAddress $Gateway | Select -First 1 -ExpandProperty InterfaceIndex
# Add network route
New-NetRoute -DestinationPrefix $Destination -NextHop $Gateway -InterfaceIndex $InterfaceIndex -RouteMetric $Metric -ErrorAction Stop -WhatIf:$CheckMode|out-null

@ -7,15 +7,20 @@
state: present
register: route
- name: check if route successfully addedd
- name: check if route successfully added
win_shell: (Get-CimInstance win32_ip4PersistedrouteTable -Filter "Destination = '{{ destination_ip_address }}'").Caption
register: route_added
- name: test if route successfully addedd
- name: check route default gateway
win_shell: (Get-CimInstance win32_ip4PersistedrouteTable -Filter "Destination = '{{ destination_ip_address }}'").NextHop
register: route_gateway
- name: test if route successfully added
assert:
that:
- route is changed
- route_added.stdout_lines[0] == "{{ destination_ip_address }}"
- route_gateway.stdout_lines[0] == "{{ default_gateway }}"
- name: add a static route to test idempotency
win_route:

Loading…
Cancel
Save