Ansible Output improvements

Using AnsibleOutput type, default type data will output 4 last lines,
while all lines would be available if needed.
This commit is contained in:
lksz 2021-05-09 23:45:23 -04:00
parent 92bd7ba69f
commit 9f0d669b4c
3 changed files with 7 additions and 4 deletions

View File

@ -40,11 +40,14 @@ Invoke-Expression $expr | ForEach-Object {
RunTime = $sw.Elapsed RunTime = $sw.Elapsed
Output = "$($res[3])".Trim() -split '\\n'; Output = "$($res[3])".Trim() -split '\\n';
}) })
$res.PSObject.TypeNames.Insert(0,"AnsibleOutput")
if( $res.Status -match '^\w+!:' ) { if( $res.Status -match '^\w+!:' ) {
[Console]::ForegroundColor = [ConsoleColor]::Red [Console]::ForegroundColor = [ConsoleColor]::Red
} else { } else {
[Console]::ForegroundColor = [ConsoleColor]::Yellow [Console]::ForegroundColor = [ConsoleColor]::Yellow
} }
$res $res
} }
[Console]::ForegroundColor = $SaveConsoleColor [Console]::ForegroundColor = $SaveConsoleColor

View File

@ -4,7 +4,4 @@
[switch]$PassThruOnly [switch]$PassThruOnly
) )
Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) -RawOutput:$RawOutput | ForEach-Object { Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) -RawOutput:$RawOutput
if( $PassThru ) { return $_ }
$_ | Select-Object Machine, RunTime, @{L='Output';E={$_.Output | Select-Object -last 4}}
}

View File

@ -0,0 +1,3 @@
Update-TypeData -TypeName "AnsibleOutput" -DefaultDisplayPropertySet 'Machine','Runtime','Output(Last 4 Lines)' -Force
Update-TypeData -TypeName "AnsibleOutput" -MemberType ScriptProperty -MemberName 'Output(Last 4 Lines)' -Value {$_.Output | Select-Object -Last 4 } -Force