The plugins/ structure is designed for collections and not the role directory structure. The name of module utils in a role directory should be Ansible.ModuleUtils.Name.ps1 and it would be referenced with #AnsibleRequires -PowerShell Ansible.ModuleUtils.Name. I highly recommend using a collection though as that is what most of the documentation is geared towards.
I solved the AnsibleRequires error with the following steps:
Add ./plugins/module_utils to module_utils in ansible.cfg.
Change the AnsibleRequires line to #AnsibleRequires -PowerShell ansible.module_utils.myapplication
Next problem: The exported command is not found:
The term 'Connect-MyApplication' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
The issue now is the name of your module util. If using the role structure module utils need to be in the format Ansible.ModuleUtils.{name}. The case doesn’t matter but your _ in .module_utils. is what is causing it to be ignored.
Because that’s a collection and that’s how the collection structure works.
Local repo (not a Galaxy collection), added as project in AWX
Unless I’m misreading what you said this meant you weren’t using a collection but trying to use the collection structure in the old role directory structure. The role structure is limited in how it works hence the rigid folder names and what a module util can be called.
What I am doing is Adding modules and plugins locally — Ansible Community Documentation
Apparently in that case, you can’t use AnsibleRequires for powershell modules? It works for Python modules (I can use from ansible.module_utils.myclient include myclient which loads the code from plugins/module_utils/myclient.py.
I don’t want to publish my code to Galaxy, so a collection is out of the question.
Please have a re read of what I’ve posted. You can use module_utils for both Python and PowerShell in the old role directory folder structure that you are using. The caveat is that the name of the module util for PowerShell utils need to be Ansible.ModuleUtils.{name} so in your example
If you want a more relaxed naming standard you MUST use a collection. You don’t need to publish a collection it can stay local to your project. If you are wanting to use a collection adjacent to a playbook it can be in the following folder structure
Since my playbooks are spread over multiple directories (per customer, per service), placing the collection at the same level as the playbooks will not work.
Renaming the module to Ansible.ModuleUtils.MyApplication.psm1 worked.
Since my playbooks are spread over multiple directories (per customer, per service), placing the collection at the same level as the playbooks will not work.
Won’t you have the same problem with the role structure? Either option allows you to package it up in a way you don’t have to distribute it public. Collections are just more flexible going forward so it is worth trying to use.