From 7cb9f09c8c902b26fbe693d9cdad5f8422778d26 Mon Sep 17 00:00:00 2001 From: lksz Date: Wed, 5 May 2021 17:57:09 -0400 Subject: [PATCH] Ansible modifications --one-line output is the default added stopwatch timing to the default output combined Status and RC into a single 2 element array, so that # of columns would default to table format Instead of -OneLine a -RawOutput switch was introduced to force full output --- ansible/Invoke-ViaAnsible.ps1 | 11 ++++++----- ansible/Pull-ViaAnsible.ps1 | 4 ++-- ansible/Update-ViaAnsible.ps1 | 5 ++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ansible/Invoke-ViaAnsible.ps1 b/ansible/Invoke-ViaAnsible.ps1 index bf11924..c898e51 100644 --- a/ansible/Invoke-ViaAnsible.ps1 +++ b/ansible/Invoke-ViaAnsible.ps1 @@ -3,7 +3,7 @@ [string[]]$Remotes = 'all', [string[]]$MoreArgs, [switch]$NotPowerShell, - [switch]$OneLine + [switch]$RawOutput ) $script:ansible_cli=@('ansible') @@ -20,7 +20,7 @@ if( $Command ) { $ansible_cli += "pwsh -encodedcommand $(ConvertTo-Base64 $($Command -join '; '))" } } -if( $OneLine ) { +if( -not $RawOutput ) { $ansible_cli += '--one-line' } $ansible_cli += $Remotes @@ -30,13 +30,14 @@ $local:expr = $('& "'+$($ansible_cli -join '" "')+'"') Write-Verbose $expr $local:SaveConsoleColor = [Console]::ForegroundColor $env:ANSIBLE_DEPRECATION_WARNINGS='false' +$local:sw = [System.Diagnostics.Stopwatch]::StartNew() Invoke-Expression $expr | ForEach-Object { - if( -not $OneLine ) { return $_ }; + if( $RawOutput ) { return $_ }; $local:res = $_.Split('|') + @('', '', '', '') $res = [PSCustomObject]([ordered]@{ Machine = $res[0].Trim(); - Status = $res[1].Trim(); - RC = "$($res[2])".Trim(); + Status = @($res[1].Trim(), "$($res[2])".Trim()) + RunTime = $sw.Elapsed Output = "$($res[3])".Trim(); }) if( $res.Status -match '^\w+!:' ) { diff --git a/ansible/Pull-ViaAnsible.ps1 b/ansible/Pull-ViaAnsible.ps1 index df5de70..08cac92 100644 --- a/ansible/Pull-ViaAnsible.ps1 +++ b/ansible/Pull-ViaAnsible.ps1 @@ -1,10 +1,10 @@ [CmdletBinding()]param( [Parameter(mandatory)] [string]$RemotePath, - [switch]$NotOneLine, + [switch]$RawOutput, [string[]]$Remotes = 'All' ) -Invoke-ViaAnsible -Command "cd $RemotePath",'Write-Output "$PWD `t"','git pull' -Remotes:$($Remotes.ToLower()) -OneLine:$(-not $NotOneLine) +Invoke-ViaAnsible -Command "cd $RemotePath",'Write-Output "$PWD `t"','git pull' -Remotes:$($Remotes.ToLower()) -RawOutput:$RawOutput diff --git a/ansible/Update-ViaAnsible.ps1 b/ansible/Update-ViaAnsible.ps1 index e3957be..805ed74 100644 --- a/ansible/Update-ViaAnsible.ps1 +++ b/ansible/Update-ViaAnsible.ps1 @@ -1,7 +1,6 @@ [CmdletBinding()]param( [string[]]$Remotes = 'All', - [switch]$OneLine - + [switch]$RawOutput ) -Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) -OneLine:$OneLine +Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) -RawOutput:$RawOutput