Created a dedicated ansible package
This commit is contained in:
parent
c6cc116564
commit
aca79c186a
4 changed files with 15 additions and 1 deletions
49
ansible/Invoke-ViaAnsible.ps1
Normal file
49
ansible/Invoke-ViaAnsible.ps1
Normal file
|
@ -0,0 +1,49 @@
|
|||
[CmdletBinding()]param(
|
||||
[string[]]$Command,
|
||||
[string[]]$Remotes = 'all',
|
||||
[string[]]$MoreArgs,
|
||||
[switch]$NotPowerShell,
|
||||
[switch]$OneLine
|
||||
)
|
||||
|
||||
$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'
|
||||
$ansible_cli += 'ANSIBLE_PYTHON_INTERPRETER=auto_silent '
|
||||
$ansible_cli += '-a'
|
||||
if( $NotPowerShell ) {
|
||||
$ansible_cli += $(($Command -join '; ').Replace("'","\`$(printf '\x27')").Replace('"',"\`$(printf '\x22')"))
|
||||
} else {
|
||||
$ansible_cli += "pwsh -encodedcommand $(ConvertTo-Base64 $($Command -join '; '))"
|
||||
}
|
||||
}
|
||||
if( $OneLine ) {
|
||||
$ansible_cli += '--one-line'
|
||||
}
|
||||
$ansible_cli += $Remotes
|
||||
$ansible_cli += $MoreArgs
|
||||
|
||||
$local:expr = $('& "'+$($ansible_cli -join '" "')+'"')
|
||||
Write-Verbose $expr
|
||||
$local:SaveConsoleColor = [Console]::ForegroundColor
|
||||
$env:ANSIBLE_DEPRECATION_WARNINGS='false'
|
||||
Invoke-Expression $expr | ForEach-Object {
|
||||
if( -not $OneLine ) { return $_ };
|
||||
$local:res = $_.Split('|') + @('', '', '', '')
|
||||
$res = [PSCustomObject]([ordered]@{
|
||||
Machine = $res[0].Trim();
|
||||
Status = $res[1].Trim();
|
||||
RC = "$($res[2])".Trim();
|
||||
Output = "$($res[3])".Trim();
|
||||
})
|
||||
if( $res.Status -match '^\w+!:' ) {
|
||||
[Console]::ForegroundColor = [ConsoleColor]::Red
|
||||
} else {
|
||||
[Console]::ForegroundColor = [ConsoleColor]::Yellow
|
||||
}
|
||||
$res
|
||||
}
|
||||
[Console]::ForegroundColor = $SaveConsoleColor
|
3
ansible/Pull-ViaAnsible.ps1
Normal file
3
ansible/Pull-ViaAnsible.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
[CmdletBinding()]param([string[]]$Remotes = 'All')
|
||||
|
||||
Invoke-ViaAnsible -Command "git pull" -Remotes:$($Remotes.ToLower())
|
3
ansible/Update-ViaAnsible.ps1
Normal file
3
ansible/Update-ViaAnsible.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
[CmdletBinding()]param([string[]]$Remotes = 'All')
|
||||
|
||||
Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower())
|
14
ansible/_.package.json
Normal file
14
ansible/_.package.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"package": {
|
||||
"Condition": [
|
||||
{
|
||||
"custom": "Get-Command ansible -Type Application",
|
||||
"System": null,
|
||||
"Hostname": null,
|
||||
"Username": null,
|
||||
"Logic": 0
|
||||
}
|
||||
],
|
||||
"Name": "ansible"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue