error executing raw on windows remote

150 views
Skip to first unread message

Thorsten Klaus

unread,
Oct 7, 2015, 9:53:50 AM10/7/15
to Ansible Project
Hi everyone,

I am already running multiple tasks using raw on my windows remote. The patch that is mentioned in previouse posts (KB2842230) is already installed.

When I am running my playbook, I am getting the following error:

Code hier eingeben...<10.0.2.176> WINRM RESULT <Response code 0, out "UploadFile.ps1 is ca", err "#< CLIXML <Objs Ver">
fatal
: [10.0.2.176] => Traceback (most recent call last):
 
File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 586, in _executor
    exec_rc
= self._executor_internal(host, new_stdin)
 
File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 789, in _executor_internal
   
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
 
File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 1036, in _executor_internal_inner
    result
= handler.run(conn, tmp, module_name, module_args, inject, complex_args)
 
File "/usr/lib/python2.7/site-packages/ansible/runner/action_plugins/raw.py", line 47, in run
    become
=self.runner.become)
 
File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 1174, in _low_level_exec_command
    in_data
=in_data)
 
File "/usr/lib/python2.7/site-packages/ansible/runner/connection_plugins/winrm.py", line 165, in exec_command
   
return (result.status_code, '', result.std_out.encode('utf-8'), result.std_err.encode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x81 in position 240: ordinal not in range(128)

Can anyone tell me how I can get the full error mentioned in the WINRM RESULT ("err "#< CLIXML <Objs Ver").

Here is my current setup:

The playbook:
- name: Upload a file to the ftp-Server.
  hosts
: builder
 
  tasks
:
   
- name: upload
      raw
: d:\PowershellScripts\UploadFile.ps1

My powershell script:
 #we specify the directory where all files that we want to upload  

$LocalFile="C:\foo.txt"    

$RemoteFile = "ftp://192.168.1.50/foo.txt"

$Username = "user"

$Password = "pass"  

# Create FTP Rquest Object

$FTPRequest = [System.Net.FtpWebRequest]::Create("$RemoteFile")

$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest

$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile

$FTPRequest.Credentials = new-object System.Net.NetworkCredential($Username, $Password)

$FTPRequest.UseBinary = $true

$FTPRequest.UsePassive = $true

# Read the File for Upload

$FileContent = gc -en byte $LocalFile

$FTPRequest.ContentLength = $FileContent.Length

# Get Stream Request by bytes

$Run = $FTPRequest.GetRequestStream()

$Run.Write($FileContent, 0, $FileContent.Length)

# Cleanup

$Run.Close()

$Run.Dispose()


Kind regards
Thorsten

J Hawkesworth

unread,
Oct 7, 2015, 10:04:05 AM10/7/15
to Ansible Project
Hi Thorsten,

running your playbook with -v or -vvvvv often helps.  I think with -vvvvv you will see more of the returned error message.

I think the problem here is maybe clash between windows path names containing \ and yaml syntax.

I suggest you try quoting the whole of the raw string and using \\ instead of \

  tasks:
    
- name: call the upload script
      raw
: 'd:\\PowershellScripts\\UploadFileTest.ps1'

You might find the script: module handy as well as that can take care of transferring the .ps1 from your ansible controller and running it.

Jon

Thorsten Klaus

unread,
Oct 8, 2015, 3:11:41 AM10/8/15
to Ansible Project
Hi Jon,

thank's a lot for your repsonse.
The script is found and executed on the remote  (The file is uploaded properly to the ftp server). But somehow this special powershell script seems to return something that indicates winrm that an error occurred.

I already found a workaround for my problem by using the basic dos command ftp.exe instead of the System.Net.FtpWebRequest in my script.

I was  wondering what information indicates winrm that an error occurred and if I could somehow try to retrieve the full message that is displayed in err = ""
(<10.0.2.176> WINRM RESULT <Response code 0, out "UploadFile.ps1 is ca", err "#< CLIXML <Objs Ver">)

The only difference I can see between an successful task and the one marked as error is that the value of "err" is not empty.

I was already trying to retrieve this message on the windows remote by calling my powershell script from another powershell script by $errror[0] was empty.

Thorsten

Trond Hindenes

unread,
Oct 8, 2015, 3:41:22 AM10/8/15
to Ansible Project
Thorsten, a good test is often to remote in to the target node from another windows machine (using psremoting and the same credentials/authentication type as you do from Ansible) and see if that causes the same error. We have seen some windows stuff behaving rather badly when used over winrm.
Reply all
Reply to author
Forward
0 new messages