mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
a74449b05f
commit
b72187cd2c
3 changed files with 10 additions and 3 deletions
2
changelogs/fragments/win_route.yaml
Normal file
2
changelogs/fragments/win_route.yaml
Normal file
|
@ -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)){
|
if (!($Route)){
|
||||||
try {
|
try {
|
||||||
# Find Interface Index
|
# 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
|
# Add network route
|
||||||
New-NetRoute -DestinationPrefix $Destination -NextHop $Gateway -InterfaceIndex $InterfaceIndex -RouteMetric $Metric -ErrorAction Stop -WhatIf:$CheckMode|out-null
|
New-NetRoute -DestinationPrefix $Destination -NextHop $Gateway -InterfaceIndex $InterfaceIndex -RouteMetric $Metric -ErrorAction Stop -WhatIf:$CheckMode|out-null
|
||||||
|
|
|
@ -7,15 +7,20 @@
|
||||||
state: present
|
state: present
|
||||||
register: route
|
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
|
win_shell: (Get-CimInstance win32_ip4PersistedrouteTable -Filter "Destination = '{{ destination_ip_address }}'").Caption
|
||||||
register: route_added
|
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:
|
assert:
|
||||||
that:
|
that:
|
||||||
- route is changed
|
- route is changed
|
||||||
- route_added.stdout_lines[0] == "{{ destination_ip_address }}"
|
- route_added.stdout_lines[0] == "{{ destination_ip_address }}"
|
||||||
|
- route_gateway.stdout_lines[0] == "{{ default_gateway }}"
|
||||||
|
|
||||||
- name: add a static route to test idempotency
|
- name: add a static route to test idempotency
|
||||||
win_route:
|
win_route:
|
||||||
|
|
Loading…
Add table
Reference in a new issue