I am working with a custom Windows module, to get a very specific piece of information living in my Windows machines.
I followed the docs, wrote a powershell module and put it in library/windows/module.ps1. However, trying to use it results in
fatal: [server.example.com]: FAILED! => {“failed”: true, “reason”: “ERROR! no action detected in task\n\nThe error appears to have been in ‘/path/to/ansible/roles/gui/tasks/client.yml’: line 12, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Get client version installed on this server\n ^ here\n”}
The task was defined as
name: Get client version installed on this server
get_client_version: path=“{{ client_path }}”
register: app_client
The error dissapears if I create an empty module called “module.py” or just “module” in library/
I searched the web and found a few similar issues reported against Ansible 1.8.x, but were fixed at the time, apparently. I’m hesitant to open a bug report since I recently opened a new one and was an already known, documented limitation. The current docs say:
Windows modules live in a “windows/” subfolder in the Ansible “library/” subtree. For example, if a module is named “library/windows/win_ping”, there will be embedded documentation in the “win_ping” file, and the actual PowerShell code will live in a “win_ping.ps1” file. Take a look at the sources and this will make more sense.
The statement above does not match what I see in Ansible 2.0.0-0.7-rc2. Putting the “module” file in library/windows still causes the error to appear, so I would say the docs need to be corrected, or maybe I’m again doing something wrong
Per the documentation, and it may not be clear, you should have both a win_ping.ps1 and a win_ping.py. The .py is an expected file, including the YAML DOCUMENTATION for the module. It may not be a requirement that you have both any more, but I am guessing based on the problem, that you must have at least one .py file in the directory in order for it to be found correctly.
Well, I moved the .ps1 to library/ and it started working just fine, no ".py" needed.
What I wrote below about the error dissapearing was correct, but at the time I was getting some problems to access my windows box. When that access was restored, trying the playbook with an empty .py file just caused ansible to fail with a "missing interpreter line" error, or something like that. So, at this point it just looks like it is better to leave the .ps1 files at library/ instead of library/windows.
If you want to pick up custom modules from more than the default /library location, you can configure this in your ansible.cfg in the [defaults]
section
#library = /usr/share/my_modules/
From what you have said it looks like it doesn’t recurse into subdirectories.