Connecting winrm module from Ansible on Linux




|



I am using ansible hosted on linux to manage both linux and Windows VMs on azure. When I try to ping windows VMs from ansible using



<br># ansible windows -m win_ping<br><br>



I am getting below error:



<br>test-windows.cloudapp.net | FAILED >> {<br>"failed": true, <br>"msg": "The term 'ConvertFrom-Json' is not recognized as the name of a cmdlet, function\r\n, script file, or operable program. Check the spelling of the name, or if a pat\r\nh was included, verify that the path is correct and try again.\r\nAt C:\\Users\\coremedia\\AppData\\Local\\Temp\\ansible-tmp-1424263716.9-1357614051035\r\n00\\win_ping.ps1:54 char:67\r\n+ $parameters = Get-Content $arguments[0] | ConvertFrom-Json <<<< ;\r\n + CategoryInfo : ObjectNotFound: (ConvertFrom-Json:String) [], Co \r\n mmandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\nThe term 'ConvertTo-Json' is not recognized as the name of a cmdlet, function, \r\nscript file, or operable program. Check the spelling of the name, or if a path \r\nwas included, verify that the path is correct and try again.\r\nAt C:\\Users\\coremedia\\AppData\\Local\\Temp\\ansible-tmp-1424263716.9-1357614051035\r\n00\\win_ping.ps1:85 char:31\r\n+ echo $obj | ConvertTo-Json <<<< -Depth 99\r\n + CategoryInfo : ObjectNotFound: (ConvertTo-Json:String) [], Comm \r\n andNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\n", <br>"parsed": false<br><br>



}



The windows machine has Powershell 4 installed.



Any Ideas?



|

I would have to say double check that you do have powershell 4 installed and operational.

That cmdlet was introduced in powershell 3.

Hi Matt,

Please find my Powershell version

Hi,

It was my mistake that I tried connecting to Windows server 2008 (PS2), whereas I am checking PS version from Windows server 2012.

Now, I upgraded Windows server 2008 poweshell version to PS3, using same steps mentioned in ansible for windows documentstion.

It successfuly pings, but when i run any other commands for like

ansible windows -m setup -vvvv

I am getting below error:

failed: [winserver.cloudapp.net] => {“failed”: true, “parsed”: false}

Process is terminated due to StackOverflowException.

STACKTRACE:

$ ansible windows -m setup -vvvv
<winserver.cloudapp.net> ESTABLISH WINRM CONNECTION FOR USER: coremedia on PORT 5986 TO winserver.cloudapp.net
<winserver.cloudapp.net> WINRM CONNECT: transport=plaintext endpoint=https://winserver.cloudapp.net:5986/wsman
<winserver.cloudapp.net> REMOTE_MODULE setup
<winserver.cloudapp.net> EXEC (New-Item -Type Directory -Path $env:temp -Name “ansible-tmp-1424429207.53-10354320142574”).FullName | Write-Host -Separator ‘’;
<winserver.cloudapp.net> WINRM EXEC ‘PowerShell’ [‘-NoProfile’, ‘-NonInteractive’, ‘-EncodedCommand’, ‘KABOAGUAdwAtAEkAdABlAG0AIAAtAFQAeQBwAGUAIABEAGkAcgBlAGMAdABvAHIAeQAgAC0AUABhAHQAaAAgACQAZQBuAHYAOgB0AGUAbQBwACAALQBOAGEAbQBlACAAIgBhAG4AcwBpAGIAbABlAC0AdABtAHAALQAxADQAMgA0ADQAMgA5ADIAMAA3AC4ANQAzAC0AMQAwADMANQA0ADMAMgAwADEANAAyADUANwA0ACIAKQAuAEYAdQBsAGwATgBhAG0AZQAgAHwAIABXAHIAaQB0AGUALQBIAG8AcwB0ACAALQBTAGUAcABhAHIAYQB0AG8AcgAgACcAJwA7AA==’]
<winserver.cloudapp.net> WINRM RESULT <Response code 0, out “C:\Users\coremedia\A”, err “”>
<winserver.cloudapp.net> PUT /tmp/tmpgISwtQ TO C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\setup
<winserver.cloudapp.net> WINRM PUT /tmp/tmpgISwtQ to C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\setup.ps1 (offset=0 size=2037)
<winserver.cloudapp.net> WINRM PUT /tmp/tmpgISwtQ to C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\setup.ps1 (offset=2037 size=2037)
<winserver.cloudapp.net> WINRM PUT /tmp/tmpgISwtQ to C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\setup.ps1 (offset=4074 size=2037)
<winserver.cloudapp.net> WINRM PUT /tmp/tmpgISwtQ to C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\setup.ps1 (offset=6111 size=2037)
<winserver.cloudapp.net> WINRM PUT /tmp/tmpgISwtQ to C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\setup.ps1 (offset=8148 size=446)
<winserver.cloudapp.net> PUT /tmp/tmpt9SWcw TO C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\arguments
<winserver.cloudapp.net> WINRM PUT /tmp/tmpt9SWcw to C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\arguments (offset=0 size=2)
<winserver.cloudapp.net> EXEC PowerShell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -File “C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\setup.ps1” “C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574\arguments”; Remove-Item "C:\Users\coremedia\AppData\Local\Temp\ansible-tmp-1424429207.53-10354320142574" -Force -Recurse;
<winserver.cloudapp.net> WINRM EXEC ‘PowerShell’ [‘-NoProfile’, ‘-NonInteractive’, ‘-EncodedCommand’, ‘UABvAHcAZQByAFMAaABlAGwAbAAgAC0ATgBvAFAAcgBvAGYAaQBsAGUAIAAtAE4AbwBuAEkAbgB0AGUAcgBhAGMAdABpAHYAZQAgAC0ARQB4AGUAYwB1AHQAaQBvAG4AUABvAGwAaQBjAHkAIABVAG4AcgBlAHMAdAByAGkAYwB0AGUAZAAgAC0ARgBpAGwAZQAgACIAQwA6AFwAVQBzAGUAcgBzAFwAYwBvAHIAZQBtAGUAZABpAGEAXABBAHAAcABEAGEAdABhAFwATABvAGMAYQBsAFwAVABlAG0AcABcAGEAbgBzAGkAYgBsAGUALQB0AG0AcAAtADEANAAyADQANAAyADkAMgAwADcALgA1ADMALQAxADAAMwA1ADQAMwAyADAAMQA0ADIANQA3ADQAXABcAHMAZQB0AHUAcAAuAHAAcwAxACIAIAAiAEMAOgBcAFUAcwBlAHIAcwBcAGMAbwByAGUAbQBlAGQAaQBhAFwAQQBwAHAARABhAHQAYQBcAEwAbwBjAGEAbABcAFQAZQBtAHAAXABhAG4AcwBpAGIAbABlAC0AdABtAHAALQAxADQAMgA0ADQAMgA5ADIAMAA3AC4ANQAzAC0AMQAwADMANQA0ADMAMgAwADEANAAyADUANwA0AFwAXABhAHIAZwB1AG0AZQBuAHQAcwAiADsAIABSAGUAbQBvAHYAZQAtAEkAdABlAG0AIAAiAEMAOgBcAFUAcwBlAHIAcwBcAGMAbwByAGUAbQBlAGQAaQBhAFwAQQBwAHAARABhAHQAYQBcAEwAbwBjAGEAbABcAFQAZQBtAHAAXABhAG4AcwBpAGIAbABlAC0AdABtAHAALQAxADQAMgA0ADQAMgA5ADIAMAA3AC4ANQAzAC0AMQAwADMANQA0ADMAMgAwADEANAAyADUANwA0AFwAIgAgAC0ARgBvAHIAYwBlACAALQBSAGUAYwB1AHIAcwBlADsA’]
<winserver.cloudapp.net> WINRM RESULT <Response code 0, out “”, err “”>
winserver.cloudapp.net | FAILED >> {
“failed”: true,
“msg”: “”,
“parsed”: false
}

Can somebody help me out please

I think I had this on a fresh Windows Server 2008 R2 installation which had not received any windows updates.
If I recall there was a bug which caused the maximum amount of memory available to processes started by powershell to be very small, which was fixed in a subsequent hotfix.
Is your windows server 2008 machine fully up to date with windows updates?

Jon

Thanks a ton you Jon. You saved me, I was struggling for a day :slight_smile:

John, do you know what update is needed? We could add it to the winrm provisioning script as a check?

This is the hotfix

http://support.microsoft.com/kb/2842230

All the best, Jon

Hi Trond, Do you have sample provisioning scrpt to check this particular windows patch? If yes, can you please share me

Not on hand for PS v3.0. I’ll need to do some digging (probably using WMI to check that the hotfix is present for 2008R2 OS machines).