From 9f0d669b4ca56bfeaa82d8c22d9d19b3581d85bd Mon Sep 17 00:00:00 2001 From: lksz Date: Sun, 9 May 2021 23:45:23 -0400 Subject: [PATCH] Ansible Output improvements Using AnsibleOutput type, default type data will output 4 last lines, while all lines would be available if needed. --- ansible/Invoke-ViaAnsible.ps1 | 3 +++ ansible/Update-ViaAnsible.ps1 | 5 +---- ansible/profile.d/TypeData.ps1 | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 ansible/profile.d/TypeData.ps1 diff --git a/ansible/Invoke-ViaAnsible.ps1 b/ansible/Invoke-ViaAnsible.ps1 index 9d5936a..4a95f87 100644 --- a/ansible/Invoke-ViaAnsible.ps1 +++ b/ansible/Invoke-ViaAnsible.ps1 @@ -40,11 +40,14 @@ Invoke-Expression $expr | ForEach-Object { RunTime = $sw.Elapsed Output = "$($res[3])".Trim() -split '\\n'; }) + $res.PSObject.TypeNames.Insert(0,"AnsibleOutput") if( $res.Status -match '^\w+!:' ) { [Console]::ForegroundColor = [ConsoleColor]::Red } else { [Console]::ForegroundColor = [ConsoleColor]::Yellow } + $res } + [Console]::ForegroundColor = $SaveConsoleColor diff --git a/ansible/Update-ViaAnsible.ps1 b/ansible/Update-ViaAnsible.ps1 index b6eeba2..257b4cc 100644 --- a/ansible/Update-ViaAnsible.ps1 +++ b/ansible/Update-ViaAnsible.ps1 @@ -4,7 +4,4 @@ [switch]$PassThruOnly ) -Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) -RawOutput:$RawOutput | ForEach-Object { - if( $PassThru ) { return $_ } - $_ | Select-Object Machine, RunTime, @{L='Output';E={$_.Output | Select-Object -last 4}} -} +Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) -RawOutput:$RawOutput diff --git a/ansible/profile.d/TypeData.ps1 b/ansible/profile.d/TypeData.ps1 new file mode 100644 index 0000000..60d136b --- /dev/null +++ b/ansible/profile.d/TypeData.ps1 @@ -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 +