diff options
Diffstat (limited to 'lib/ansible/plugins/shell/powershell.py')
-rw-r--r-- | lib/ansible/plugins/shell/powershell.py | 45 |
1 files changed, 7 insertions, 38 deletions
diff --git a/lib/ansible/plugins/shell/powershell.py b/lib/ansible/plugins/shell/powershell.py index aba3183e76..0e16d34e16 100644 --- a/lib/ansible/plugins/shell/powershell.py +++ b/lib/ansible/plugins/shell/powershell.py @@ -112,41 +112,12 @@ class ShellModule(object): cmd_parts.insert(0, '&') elif shebang and shebang.startswith('#!'): cmd_parts.insert(0, shebang[2:]) - script = ''' - Try - { - %s - } - Catch - { - $_obj = @{ failed = $true } - If ($_.Exception.GetType) - { - $_obj.Add('msg', $_.Exception.Message) - } - Else - { - $_obj.Add('msg', $_.ToString()) - } - If ($_.InvocationInfo.PositionMessage) - { - $_obj.Add('exception', $_.InvocationInfo.PositionMessage) - } - ElseIf ($_.ScriptStackTrace) - { - $_obj.Add('exception', $_.ScriptStackTrace) - } - Try - { - $_obj.Add('error_record', ($_ | ConvertTo-Json | ConvertFrom-Json)) - } - Catch - { - } - Echo $_obj | ConvertTo-Json -Compress -Depth 99 - Exit 1 - } - ''' % (' '.join(cmd_parts)) + catch = ''' + $_obj = @{ failed = $true; $msg = $_ } + echo $_obj | ConvertTo-Json -Compress -Depth 99 + Exit 1 + ''' + script = 'Try { %s }\nCatch { %s }' % (' '.join(cmd_parts), 'throw') if rm_tmp: rm_tmp = self._escape(self._unquote(rm_tmp)) rm_cmd = 'Remove-Item "%s" -Force -Recurse -ErrorAction SilentlyContinue' % rm_tmp @@ -178,11 +149,9 @@ class ShellModule(object): replace = lambda m: substs[m.lastindex - 1] return re.sub(pattern, replace, value) - def _encode_script(self, script, as_list=False, strict_mode=True): + def _encode_script(self, script, as_list=False): '''Convert a PowerShell script to a single base64-encoded command.''' script = to_unicode(script) - if strict_mode: - script = u'Set-StrictMode -Version Latest\r\n%s' % script script = '\n'.join([x.strip() for x in script.splitlines() if x.strip()]) encoded_script = base64.b64encode(script.encode('utf-16-le')) cmd_parts = _common_args + ['-EncodedCommand', encoded_script] |