Powershell Ansible modules with Linux

We have several existing Powershell scripts that we wanted to adapt to use with Ansible. Mostly dealing with VMware and so they don’t specifically need a Windows OS.

We didn’t want to just use the win_powershell command since it is tricky to securely pass secrets into the scripts, so we adapted several of the scripts into full Ansible modules as Powershell files so we could no_log the passwords. But this requires us to still run this on a Windows host due to the #!powershell at the top of the file.

We would rather install Powershell 7 inside of our Execution Environment along with the powershell modules and still use a .ps1 based Ansible module to run completely inside of the Linux based EE to eliminate the delegate host to send it to Windows.

Is there a standard way to do this at this time? When we last looked a year or so ago there wasn’t a supported way. We found one third party repo that had a modified file to start to allow this, but not much movement on that front.

From this link:

I saw “Ansible modules can be written in any language that can return JSON, such as Ruby, Python, or bash.” but that doesn’t appear to include Powershell even if Powershell is available on the Linux box that is running Ansible, but I’m hoping I’ve missed something.

I’ve talked about this recently with Unable to create a powershell module that forces usage of pwsh/powershell core/powershell 7 · Issue #82432 · ansible/ansible · GitHub. While that comment focuses on pwsh.exe on Windows it also applies to pwsh on non-Windows (except the win_powershell option).

In short you can use PowerShell modules but you won’t have access to any of the shared module_utils that the Windows PowerShell modules have access to.

Thats not exactly true. One can use the legacy modules and I did a proof of concept with it. I wrote a post to it [here].
(Ansible - PowerShell on Linux using Legacy modules and helper functions)