Collection: adding ps1 script breaks anisble_connection=local?

Hi,

I’m running into something weird, that is maybe a bug, but I would like to check this before reporting it.

I’m working on the Ansible jcliff collection and we recently added a ps1 script to our modules to support windows. However, now, the collection seems to be broken if I use it locally (host: localhost) :

fatal: [localhost]: FAILED! => {“changed”: false, “module_stderr”: “/bin/sh: powershell: command not found\n”, "…

As I am running on Linux, I don’t know why powershell is being looked up…

Is it a known issue? Do you see a possible workaroung? Maybe simply a way to use the install phase of “ansible-galaxy collection install” to remove/rename the ps1 script if being installed on Linux?

Thanks!

Friendly reminder : nobody ran into this issue before? I’ve seen some indication that people behind the module slurp has similar issue, but there was no clear fix…

Hi Romain,

I checked Ansible jcliff collection and as you added .ps1(for windows) script with the same module name as the .py(for Linux), Ansible considers the first module file i.e. jcliff.ps1 even when executing against a Linux node.

As native Ansible Windows modules prefixed with "win_", I would recommend you to modify the file name jcliff.ps1 to win_jcliff.ps1 to avoid confusion.

Regards,
Ompragash

Oh gosh, it’s that simple! Cool :slight_smile: we’ll do that then, thanks.

Hi,

Thanks for pointing this out! We’ve indeed separated the Windows scripts (see windows_support branch) from the regular python scripts, but it leads to awful a lot of code duplication :frowning: . We need to duplicate both the plugins/module/jcliff.py (into its own .ps1), but, as it turns out, we also need to have the plugins/actions/jcliff.py to be fully duplicated :frowning: … Did we miss something here? If not, is there a way to enhance the “ansible-collection build” phase to generate (ie $ cp plugins/action/jcliff.py → win_jcliff.ps1) the required duplicated files?

I have a feeling we are not on the right track here…