Running PowerCli scripts within PowerShell scripts in Ansible

Folks,
I have an Ansible server and a Windows PowerShell server with PowerCli.
I encapsulate PowerCli commands within PowerShell scripts and call them in Ansible.

It works on one Windows server and doesn’t on another.
Getting error as below
"Connect-VIServer Exception \r\nof type ‘System.OutOfMemoryException’ was thrown.

NotSpecified: (:slight_smile: [Connect-VIServer], ViError\r\n+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Excep \r\ntion,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer\r\n\r\nGet-Datacenter : Get-Datacenter
You are not \r\ncurrently connected to any servers. Please connect first using a Connect \r\ncmdlet"

Is there any requirements that I need to follow?
I’m able to run normal powershell scripts via ansible on both windows servers and am able to run powercli commands within the windows servers.

Kindly suggest.

Regards,
Rajesh

Hi Rajesh,

I have seen System.OutOfMemoryException thrown on Windows Server 2008 R2 which has not yet had windows updates applied.
I don’t know PowerCli so i don’t know if it requires large memory allocation (winrm sets quotas on memory, cpu etc - see
https://msdn.microsoft.com/en-us/library/ee309367(v=vs.85).aspx - so it is possible you might need to increase one or more quota settings.

Also it might be worth trying vmware_guest module and connecting from your ansible controller to vSphere directly, rather than going via a windows host.

Hope this helps,

Jon

Hi Jon,
I need to use this method since i need to work with multiple VMware products like vCenter, vCloud Director, VCNS etc.
I believe there are no modules yet for vCloud Director and VCNS. Kindly suggest if there are alternatives.

For my issue here is what i did.
The powercli version on the host that was running fine was 6.0 Release 1.
In the new host i remove the latest powercli which is 6.5 Release 1 and installed 6.0 Release 1.
It started working.

I checked that 6.0 has both snapin’s as well as modules. In 6.5 we only have modules (VMware migrated from snapins to modules)
I’m not sure but probably Ansible needs snapin’s in order to work.

Any suggestions or thoughts?

Regards,
Rajesh

Hi,

I am not aware of modules for the vmware products you mention.

I don't know why things are working with 6.0 but not 6.5. My guess is 6.5 is perhaps just using more memory than 6.0 and so you are hitting the memory usage quota.

Jon

Old thread, but some newer tools have come out since. Not sure the status of vCNS, but NSX seems to be decently covered with some of these tools. Look at these:

Oh and PowerCLI 10.0.0 has Linux support, also, so you could run it from your Ansible control machine.

I have been running PowerShell Core 6.0.1 with PowerCLI 10.0.0 on Linux and it has been working pretty well so far. I have been using it so I can use vSphere tags in a dynamic inventory (similar to vmware_inventory.py).