From 9aa6c44473e82855e1559f6e9409b3e5e40c2ee0 Mon Sep 17 00:00:00 2001 From: Trond Hindenes Date: Fri, 29 Aug 2014 10:39:42 +0200 Subject: [PATCH] All changes referenced in PRs #8767 , #8768 , #8769 : This changes the get-attr function slightly, and lets the module specify whether a param is needed and auto-fails if it is not present. A module can now verify params like so:: $params = Parse-Args $args; $result = New-Object psobject; Set-Attr $result "changed" $false; $path = Get-Attr -obj $params -name path -failifempty $true -resultobj $result or $params = Parse-Args $args; $result = New-Object psobject; Set-Attr $result "changed" $false; $path = Get-Attr -obj $params -name path -failifempty $true -emptyattributefailmessage "Oh man. You forgot the main part!" -resultobj $result slight tweak in how the powershell module converts to json in order to support nested objects (allows for more complex facts, among others) This script gathers some extended facts on windows hosts in a json array attribute called "ansible_interfaces". This info is needed for some network-related modules I'm working on. Required the update to powershell.ps1 to return deeply nested json objects. --- windows/setup.ps1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/windows/setup.ps1 b/windows/setup.ps1 index bd4718310d9..381fc973c5f 100644 --- a/windows/setup.ps1 +++ b/windows/setup.ps1 @@ -32,6 +32,27 @@ $capacity = 0 $memory | foreach {$capacity += $_.Capacity} $netcfg = Get-WmiObject win32_NetworkAdapterConfiguration +$ActiveNetcfg = @(); $ActiveNetcfg+= $netcfg | where {$_.ipaddress -ne $null} +$formattednetcfg = @() +foreach ($adapter in $ActiveNetcfg) +{ + $thisadapter = New-Object psobject @{ + interface_name = $adapter.description + dns_domain = $adapter.dnsdomain + default_gateway = $null + interface_index = $adapter.InterfaceIndex + } + + if ($adapter.defaultIPGateway) + { + $thisadapter.default_gateway = $adapter.DefaultIPGateway[0].ToString() + } + + $formattednetcfg += $thisadapter;$thisadapter = $null +} + +Set-Attr $result.ansible_facts "ansible_interfaces" $formattednetcfg + Set-Attr $result.ansible_facts "ansible_hostname" $env:COMPUTERNAME; Set-Attr $result.ansible_facts "ansible_fqdn" "$([System.Net.Dns]::GetHostByName((hostname)).HostName)" Set-Attr $result.ansible_facts "ansible_system" $osversion.Platform.ToString()