[WIN] Howto built custom Powershell module. Read docs, but not getting it.

47 views
Skip to first unread message

acropia

unread,
Jun 23, 2015, 9:55:57 AM6/23/15
to ansible...@googlegroups.com
Hi,

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.

Any clues?

J Hawkesworth

unread,
Jun 23, 2015, 10:03:35 AM6/23/15
to ansible...@googlegroups.com
I have a custom library path defined in the [defaults] section in my /etc/ansible/ansible.cfg file, like this:

library        = /etc/ansible/library

Not sure if this is required but I use a few custom modules which are in this folder.

What ansible version are you using?

Trond Hindenes

unread,
Jun 23, 2015, 10:11:03 AM6/23/15
to ansible...@googlegroups.com
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.

In your example, this should work:

---
- name: Test windows
  hosts: all
  tasks:
    - win_test:
        data: "Hello from win_test"
    - name: Another way to specify a play
      win_test: data="Hello2 from win_test"

acropia

unread,
Jun 24, 2015, 4:32:48 AM6/24/15
to ansible...@googlegroups.com
I use Ansible 1.9.1 on CentOS Linux 7.1.

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)?


Op dinsdag 23 juni 2015 16:11:03 UTC+2 schreef Trond Hindenes:
Reply all
Reply to author
Forward
0 new messages