diff options
author | Jordan Borean <jborean93@gmail.com> | 2018-04-06 07:36:38 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-06 07:36:38 +1000 |
commit | fd4d264253f6faba2fb30b4a3c469e13d411d0fc (patch) | |
tree | bc4f1ced46bf9b280dd396df9633ef9634419f71 | |
parent | ad94d03ba1a2771e0b7e88e2083a4507a2767862 (diff) | |
download | ansible-fd4d264253f6faba2fb30b4a3c469e13d411d0fc.tar.gz |
win_setup: Added connection name to interfaces (#37327)
-rw-r--r-- | lib/ansible/modules/windows/setup.ps1 | 21 | ||||
-rw-r--r-- | test/integration/targets/win_setup/tasks/main.yml | 2 |
2 files changed, 20 insertions, 3 deletions
diff --git a/lib/ansible/modules/windows/setup.ps1 b/lib/ansible/modules/windows/setup.ps1 index ae618d8fd4..fe67ce289f 100644 --- a/lib/ansible/modules/windows/setup.ps1 +++ b/lib/ansible/modules/windows/setup.ps1 @@ -44,9 +44,9 @@ Function Get-MachineSid { $cim_instances = @{} -Function Get-LazyCimInstance([string]$instance_name) { +Function Get-LazyCimInstance([string]$instance_name, [string]$namespace="Root\CIMV2") { if(-not $cim_instances.ContainsKey($instance_name)) { - $cim_instances[$instance_name] = $(Get-CimInstance $instance_name) + $cim_instances[$instance_name] = $(Get-CimInstance -Namespace $namespace -ClassName $instance_name) } return $cim_instances[$instance_name] @@ -229,15 +229,26 @@ if($gather_subset.Contains('facter')) { if($gather_subset.Contains('interfaces')) { $netcfg = Get-LazyCimInstance Win32_NetworkAdapterConfiguration - $ActiveNetcfg = @() $ActiveNetcfg += $netcfg | where {$_.ipaddress -ne $null} + $namespaces = Get-LazyCimInstance __Namespace -namespace root + if ($namespaces | Where-Object { $_.Name -eq "StandardCimv" }) { + $net_adapters = Get-LazyCimInstance MSFT_NetAdapter -namespace Root\StandardCimv2 + $guid_key = "InterfaceGUID" + $name_key = "Name" + } else { + $net_adapters = Get-LazyCimInstance Win32_NetworkAdapter + $guid_key = "GUID" + $name_key = "NetConnectionID" + } + $formattednetcfg = @() foreach ($adapter in $ActiveNetcfg) { $thisadapter = @{ default_gateway = $null + connection_name = $null dns_domain = $adapter.dnsdomain interface_index = $adapter.InterfaceIndex interface_name = $adapter.description @@ -248,6 +259,10 @@ if($gather_subset.Contains('interfaces')) { { $thisadapter.default_gateway = $adapter.DefaultIPGateway[0].ToString() } + $net_adapter = $net_adapters | Where-Object { $_.$guid_key -eq $adapter.SettingID } + if ($net_adapter) { + $thisadapter.connection_name = $net_adapter.$name_key + } $formattednetcfg += $thisadapter } diff --git a/test/integration/targets/win_setup/tasks/main.yml b/test/integration/targets/win_setup/tasks/main.yml index 516fbb4130..92f9a23444 100644 --- a/test/integration/targets/win_setup/tasks/main.yml +++ b/test/integration/targets/win_setup/tasks/main.yml @@ -45,6 +45,7 @@ - setup_result.ansible_facts.ansible_interfaces - setup_result.ansible_facts.ansible_interfaces[0] - setup_result.ansible_facts.ansible_interfaces[0].interface_name + - setup_result.ansible_facts.ansible_interfaces[0].connection_name - setup_result.ansible_facts.ansible_interfaces[0].interface_index - setup_result.ansible_facts.ansible_architecture - setup_result.ansible_facts.ansible_os_name @@ -114,6 +115,7 @@ - setup_result.ansible_facts.ansible_interfaces - setup_result.ansible_facts.ansible_interfaces[0] - setup_result.ansible_facts.ansible_interfaces[0].interface_name + - setup_result.ansible_facts.ansible_interfaces[0].connection_name - setup_result.ansible_facts.ansible_interfaces[0].interface_index - setup_result.ansible_facts.keys() | union(['ansible_interfaces','gather_subset','module_setup']) | length == 3 |