From b72187cd2c412af3a052d28cab9f4c7671ef281e Mon Sep 17 00:00:00 2001 From: uberjew666 Date: Thu, 6 Dec 2018 03:39:06 +0000 Subject: [PATCH] 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 --- changelogs/fragments/win_route.yaml | 2 ++ lib/ansible/modules/windows/win_route.ps1 | 2 +- test/integration/targets/win_route/tasks/tests.yml | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/win_route.yaml diff --git a/changelogs/fragments/win_route.yaml b/changelogs/fragments/win_route.yaml new file mode 100644 index 0000000000..6a013c563e --- /dev/null +++ b/changelogs/fragments/win_route.yaml @@ -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 diff --git a/lib/ansible/modules/windows/win_route.ps1 b/lib/ansible/modules/windows/win_route.ps1 index 895d97d7f0..d2fe5cf989 100644 --- a/lib/ansible/modules/windows/win_route.ps1 +++ b/lib/ansible/modules/windows/win_route.ps1 @@ -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 diff --git a/test/integration/targets/win_route/tasks/tests.yml b/test/integration/targets/win_route/tasks/tests.yml index e893dfd639..0c365bef54 100644 --- a/test/integration/targets/win_route/tasks/tests.yml +++ b/test/integration/targets/win_route/tasks/tests.yml @@ -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: