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
This commit is contained in:
lksz 2021-05-05 17:57:09 -04:00
parent 35fe3a156f
commit 7cb9f09c8c
3 changed files with 10 additions and 10 deletions

View File

@ -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+!:' ) {

View File

@ -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

View File

@ -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