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.
This commit is contained in:
parent
9c172df595
commit
9aa6c44473
1 changed files with 21 additions and 0 deletions
|
@ -32,6 +32,27 @@ $capacity = 0
|
||||||
$memory | foreach {$capacity += $_.Capacity}
|
$memory | foreach {$capacity += $_.Capacity}
|
||||||
$netcfg = Get-WmiObject win32_NetworkAdapterConfiguration
|
$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_hostname" $env:COMPUTERNAME;
|
||||||
Set-Attr $result.ansible_facts "ansible_fqdn" "$([System.Net.Dns]::GetHostByName((hostname)).HostName)"
|
Set-Attr $result.ansible_facts "ansible_fqdn" "$([System.Net.Dns]::GetHostByName((hostname)).HostName)"
|
||||||
Set-Attr $result.ansible_facts "ansible_system" $osversion.Platform.ToString()
|
Set-Attr $result.ansible_facts "ansible_system" $osversion.Platform.ToString()
|
||||||
|
|
Loading…
Reference in a new issue