I want to built some custom modules for Windows. But I ran into some problems:
When I read the docs about developing modules, the part about test-module (git clone, source, chmod) is breaking my Ansible installation. I can’t find out on which path I have to execute those commands
When I copy a module like the win_ping module inside /usr/lib/python2.7/site-packages/ansible/modules/core/ I can execute it with:
`
ansible windows -m my_test
`
But when I try to use the modul inside a playbook, like:
`
name: Testmodule
my_test: var=value
`
I get an error “my_test is not a legal parameter in an Ansible task or handler”.
I have read about a subdictory ‘./library’ which I creates in /etc/ansible/library. But placing my module over there doesn’t work.
Hi,
A good way to start is just like you’re doing, copying the win_ping file. I’d recommend using a custom library path like J H describes above.
A module consists of two files, a .ps1 file which is the actual script and a corresponding .py file. On Windows the py file is only used for documentation, but it still needs to be available.
Looking at the documentation for win_ping that module only lists “data” as an acceptable parameter, so passing “var” to it won’t work without modification.
One thing that can easily throw you when getting started with ansible is the yml syntax. Yml uses indenting to organize stuff into arrays/lists, so if your indentation is wrong you’ll get strange errors.
I just added a win_test.py file with DOCUMENTATION and EXAMPLES. And now I can use the module like:
`
name: Win test module
win_test:
var: value
`
I did not put the library option inside my ansible.cfg, because the documentation states the subdir ‘library’ is automatically searched by Ansible.
The one thing that doesn’t for now is the test-module command.
Trond, I read your work for different Windows modules, so how did you get the test-module command to work? At which path you execute the commands in the docs (git clone, source, chmod)?