Theoretically this is all possible but there are a few things that are 
impediments to getting this all working.

   - Python modules can technically run on Windows but our general 
   module_utils (basic.py) use libraries that are
   - PowerShell modules can technically run on non-Windows but a lot of the 
   mechanisms to get it running assume the target is Windows
   
This essentially means to use either one on both platforms you will have to 
give up on using the shared module_utils which makes managing options and 
emitting the output a lot simpler than doing it manually.

I know there have been some unofficial attempts at getting PowerShell 
working on non-Windows with the module_utils but it uses some internal 
mechanisms so it isn't guaranteed to work across newer Ansible versions. In 
saying that you can write cross platform modules for both platforms, you 
just can't use any of the shared module_utils available 
https://github.com/ansible/ansible/issues/48881#issuecomment-440481672.

Thanks

Jordan


On Wednesday, August 23, 2023 at 6:15:19 AM UTC+10 michie wrote:

> Hello,
>
> I've created two modules-- one in Python and one in PowerShell for each of 
> my remote machines. Of course, as expected, the Python one can run only on 
> the remote Linux and the PowerShell-written module can only be used on the 
> remote Windows system.
>
> I understand that Python modules can't be run on Windows 
> <https://docs.ansible.com/ansible/latest/os_guide/windows_faq.html#can-i-run-python-modules-on-windows-hosts>
>  
> because winRM will only accept PowerShell modules. However, I managed to 
> connect my remote Windows server to my Linux control client via SSH. 
> Ansible picks it up perfectly and I haven't run into any issues despite it 
> being an experimental feature. This still causes me errors and the python 
> module doesn't run the same way it does on Linux. Why? Is there anything 
> else I could try so that my custom Python module can be run on both OS's? I 
> know that there are some modules from ansible-core that can be run on both 
> systems-- how can I do that with my custom modules?
>
> If running a custom python module on windows is a big no-no, how can I get 
> my custom PowerShell module to run on Linux? I know that modules can be 
> written in any language, but why can't Linux take in the PowerShell module? 
> Are there some changes or settings that I can set to make to instruct 
> ansible to use PowerShell in Linux? I also have PowerShell downloaded on 
> that remote linux machine.
>
> Any suggestions are greatly appreciated! This will save me a lot of time 
> just creating one module instead of two for my two remote systems. 
>
> Thanks!
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d6601fd5-8cf6-4496-963b-d8ac4b4f2ffdn%40googlegroups.com.

Reply via email to