From b1980e5820b2f09ac1723579d0d7108180d5ade9 Mon Sep 17 00:00:00 2001 From: lksz Date: Sun, 1 Nov 2020 00:55:38 -0400 Subject: [PATCH] Ansible support + sz-update alias --- Aliases/sz-update.ps1 | 1 + Invoke-ViaAnsible.ps1 | 19 +++++++++++++++++++ Pull-ViaAnsible.ps1 | 3 +++ Update-ViaAnsible.ps1 | 3 +++ 4 files changed, 26 insertions(+) create mode 100644 Aliases/sz-update.ps1 create mode 100644 Invoke-ViaAnsible.ps1 create mode 100644 Pull-ViaAnsible.ps1 create mode 100644 Update-ViaAnsible.ps1 diff --git a/Aliases/sz-update.ps1 b/Aliases/sz-update.ps1 new file mode 100644 index 0000000..c680027 --- /dev/null +++ b/Aliases/sz-update.ps1 @@ -0,0 +1 @@ +Update-OSz diff --git a/Invoke-ViaAnsible.ps1 b/Invoke-ViaAnsible.ps1 new file mode 100644 index 0000000..3f1425d --- /dev/null +++ b/Invoke-ViaAnsible.ps1 @@ -0,0 +1,19 @@ +[CmdletBinding()]param([string[]]$Command, [switch]$NotPowerShell, [string[]]$Remotes) + +$script:ansible_cli=@('ansible') +if( (Test-Path './ansible.cfg') -or (Test-Path '/opt/ansible/hosts') -and (Test-Path '/opt/ansible/ssh_key_for_ansible') ) { + $ansible_cli += '-i', '/opt/ansible/hosts', '--private-key=/opt/ansible/ssh_key_for_ansible' +} +if( $Command ) { + $ansible_cli += '-a' + if( $NotPowerShell ) { + $ansible_cli += $(($Command -join '; ').Replace("'","\`$(printf '\x27')").Replace('"',"\`$(printf '\x22')")) + } else { + $ansible_cli += "pwsh -encodedcommand $(ConvertTo-Base64 $($Command -join '; '))" + } +} +$ansible_cli += $Remotes + +$local:expr = $('& "'+$($ansible_cli -join '" "')+'"') +Write-Verbose $expr +Invoke-Expression $expr diff --git a/Pull-ViaAnsible.ps1 b/Pull-ViaAnsible.ps1 new file mode 100644 index 0000000..8b53770 --- /dev/null +++ b/Pull-ViaAnsible.ps1 @@ -0,0 +1,3 @@ +[CmdletBinding()]param([string[]]$Remotes = 'All') + +Invoke-ViaAnsible -Command "git pull" -Remotes:$($Remotes.ToLower()) diff --git a/Update-ViaAnsible.ps1 b/Update-ViaAnsible.ps1 new file mode 100644 index 0000000..7433136 --- /dev/null +++ b/Update-ViaAnsible.ps1 @@ -0,0 +1,3 @@ +[CmdletBinding()]param([string[]]$Remotes = 'All') + +Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower())