mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Complete rewrite of Windows exec wrapper (#21510)
* supports pipelining for faster execution * supports become (runas), creates interactive subsession under WinRM batch logon * supports usage of arbitrary module_utils files * modular exec wrapper payload supports easier extension * integrates async wrapper behavior for pipelined/become'd async * module_utils are loaded as true Powershell modules, no more runtime modifications to module code
This commit is contained in:
@@ -27,15 +27,7 @@
|
||||
#
|
||||
|
||||
Set-StrictMode -Version 2.0
|
||||
|
||||
# Ansible v2 will insert the module arguments below as a string containing
|
||||
# JSON; assign them to an environment variable and redefine $args so existing
|
||||
# modules will continue to work.
|
||||
$complex_args = @'
|
||||
<<INCLUDE_ANSIBLE_MODULE_JSON_ARGS>>
|
||||
'@
|
||||
Set-Content env:MODULE_COMPLEX_ARGS -Value $complex_args
|
||||
$args = @('env:MODULE_COMPLEX_ARGS')
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Helper function to set an "attribute" on a psobject instance in powershell.
|
||||
# This is a convenience to make adding Members to the object easier and
|
||||
@@ -161,7 +153,7 @@ Function Get-AnsibleParam($obj, $name, $default = $null, $resultobj = @{}, $fail
|
||||
|
||||
# Iterate over aliases to find acceptable Member $name
|
||||
foreach ($alias in $aliases) {
|
||||
if (Get-Member -InputObject $obj -Name $alias) {
|
||||
if ($obj.ContainsKey($alias)) {
|
||||
$found = $alias
|
||||
break
|
||||
}
|
||||
@@ -217,7 +209,6 @@ If (!(Get-Alias -Name "Get-attr" -ErrorAction SilentlyContinue))
|
||||
New-Alias -Name Get-attr -Value Get-AnsibleParam
|
||||
}
|
||||
|
||||
|
||||
# Helper filter/pipeline function to convert a value to boolean following current
|
||||
# Ansible practices
|
||||
# Example: $is_true = "true" | ConvertTo-Bool
|
||||
@@ -251,6 +242,9 @@ Function Parse-Args($arguments, $supports_check_mode = $false)
|
||||
{
|
||||
$params = Get-Content $arguments[0] | ConvertFrom-Json
|
||||
}
|
||||
Else {
|
||||
$params = $complex_args
|
||||
}
|
||||
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
||||
If ($check_mode -and -not $supports_check_mode)
|
||||
{
|
||||
@@ -314,4 +308,7 @@ Function Get-PendingRebootStatus
|
||||
{
|
||||
return $False
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# this line must stay at the bottom to ensure all defined module parts are exported
|
||||
Export-ModuleMember -Alias * -Function * -Cmdlet *
|
||||
Reference in New Issue
Block a user