Open spectras opened 2 years ago
Sorry for the delay in looking at this issue. It seems like the problem is not just about virtual interfaces as the tests in CI run on a virtual loopback adapter and testing locally doesn't seem to bring up the problem you are seeing
PS C:\Windows\system32> Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'InterfaceIndex = 16' -Property DNSServerSearchOrder, IPEnabled, SettingID | Select-Object -Property DNSServerSearchOrder, IPEnabled, @{ N = 'InterfaceGuid'; E = { $_.SettingId } }
DNSServerSearchOrder IPEnabled InterfaceGuid
-------------------- --------- -------------
True {2C9EF0FA-B966-47AC-9E5A-518931B949EA}
In the above example InterfaceIndex
is the loopback virtual adapter I've added for testing and it definitely returns the output as expected. I also copied and ran that function manually on my host and can verify that it doesn't fail
PS C:\Windows\system32> Get-NetAdapterInfo
Name InterfaceIndex InterfaceGuid RegInfo
---- -------------- ------------- -------
Ethernet 12 {864AA09D-872B-42C2-A3D2-C32D3CA3A177}
VirtAdapter 16 {2C9EF0FA-B966-47AC-9E5A-518931B949EA}
Ethernet 2 5 {0D60B040-DA3B-478A-BD35-41514BBEC027}
At a guess it's not specifically a virtual adapter that's problematic here but something specific about this type of virtual adapter the code needs to handle better. Are you able to provide the following:
Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration
at allA simple workaround is to change the if statement to something like if (-not $adapter_config -or $adapter_config.IPEnabled -eq $false) {
but it would be good to figure out what specifically about your adapter is causing the problem here.
SUMMARY
The powershell script used by win_dns_client inspects the configuration of all interfaces. Virtual Ethernet adapters, however, do not seem to be valid in that context.
The error is a bit misleading, as a quick test shows
$adapter_info
is $null becauseGet-CimInstance
returned $null here: https://github.com/ansible-collections/ansible.windows/blob/main/plugins/modules/win_dns_client.ps1#L139ISSUE TYPE
COMPONENT NAME
ansible.windows.win_dns_client, in the powershell script.
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Running Ubuntu 21.10 inside WSL1 on Windows 10.
Target VM is Windows Server 2022 Datacenter, 10.0.20348.0
Target VM has Hyper-V feature installed, which creates a virtual ethernet adapter
STEPS TO REPRODUCE
The problems shows up when using
*
as adapter name, as the virtual adapter gets enumerated.EXPECTED RESULTS
Configuration is done. I think skipping virtual adapters would be fine as they do not seem configurable.
ACTUAL RESULTS
I seems virtual ethernet adapters do not have valid configuration objects from Get-CimInstance, making it return null. Then when the scripts tries to read properties, an exception is thrown.
Full error message below:
Specifying just the physical adapter names explicitly in
adapter_names
works around the problem.